Commit 8d22684c authored by Massimiliano's avatar Massimiliano
Browse files

Cleaned up code for better maintenance+

Made Third party links klickable+
Made application&device info fully translatable
parent af8bcd6a
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<codeStyleSettings language="XML">
<indentOptions>
<option name="CONTINUATION_INDENT_SIZE" value="4" />
</indentOptions>
<arrangement>
<rules>
<section>
<rule>
<match>
<AND>
<NAME>xmlns:android</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>xmlns:.*</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
<order>BY_NAME</order>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*:id</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*:name</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>name</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>style</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
<order>BY_NAME</order>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
</AND>
</match>
<order>ANDROID_ATTRIBUTE_ORDER</order>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>.*</XML_NAMESPACE>
</AND>
</match>
<order>BY_NAME</order>
</rule>
</section>
</rules>
</arrangement>
</codeStyleSettings>
</code_scheme>
</component>
\ No newline at end of file
......@@ -6,8 +6,8 @@ android {
applicationId "org.disroot.disrootapp"
minSdkVersion 15
targetSdkVersion 28
versionCode 21
versionName "1.2.2"
versionCode 22
versionName "1.2.3"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
......@@ -35,7 +35,7 @@ dependencies {
//noinspection GradleCompatible
implementation 'com.android.support:customtabs:28.0.0'
//noinspection GradleCompatible
implementation 'com.android.support:cardview-v7:27.1.1'
implementation 'com.android.support:cardview-v7:28.0.0'
}
dependencies {
......@@ -46,5 +46,5 @@ repositories {
}
dependencies {
implementation 'com.android.support.constraint:constraint-layout:+'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
}
......@@ -29,7 +29,8 @@ import java.util.HashMap;
import java.util.Timer;
import java.util.TimerTask;
import static android.support.constraint.motion.MotionScene.TAG;
import static android.support.constraint.Constraints.TAG;
public class StatusService extends Service {
......
......@@ -4,23 +4,22 @@ package org.disroot.disrootapp.ui;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.TabLayout;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.text.method.LinkMovementMethod;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.TextView;
......@@ -28,7 +27,9 @@ import android.widget.TextView;
import org.disroot.disrootapp.R;
import org.disroot.disrootapp.utils.Constants;
import static org.disroot.disrootapp.BuildConfig.*;
import static org.disroot.disrootapp.BuildConfig.APPLICATION_ID;
import static org.disroot.disrootapp.BuildConfig.VERSION_CODE;
import static org.disroot.disrootapp.BuildConfig.VERSION_NAME;
public class AboutActivity extends AppCompatActivity {
......@@ -74,14 +75,13 @@ public class AboutActivity extends AppCompatActivity {
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Uri uri = Uri.parse(String.valueOf(Constants.URL_SUPPORT));
Uri uri = Uri.parse(Constants.URL_SUPPORT);
Intent support = new Intent(Intent.ACTION_VIEW, Uri.parse(String.valueOf(uri)));
startActivity(support);
// Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
// .setAction("Action", null).show();
}
});
}
......@@ -152,7 +152,7 @@ public class AboutActivity extends AppCompatActivity {
ContributeBtn.setOnClickListener(new View.OnClickListener()
{
public void onClick(View arg0) {
Uri uri = Uri.parse(String.valueOf(Constants.URL_SOURCE));
Uri uri = Uri.parse(Constants.URL_SOURCE);
Intent code = new Intent(Intent.ACTION_VIEW, Uri.parse(String.valueOf(uri)));
startActivity(code);
}
......@@ -162,7 +162,7 @@ public class AboutActivity extends AppCompatActivity {
TranslateBtn.setOnClickListener(new View.OnClickListener()
{
public void onClick(View arg0) {
Uri uri = Uri.parse(String.valueOf(Constants.URL_TRANSLATE));
Uri uri = Uri.parse(Constants.URL_TRANSLATE);
Intent translate = new Intent(Intent.ACTION_VIEW, Uri.parse(String.valueOf(uri)));
startActivity(translate);
}
......@@ -173,7 +173,7 @@ public class AboutActivity extends AppCompatActivity {
FeedbackBtn1.setOnClickListener(new View.OnClickListener()
{
public void onClick(View arg0) {
Uri uri = Uri.parse(String.valueOf(Constants.URL_BUGS));
Uri uri = Uri.parse(Constants.URL_BUGS);
Intent feedback1 = new Intent(Intent.ACTION_VIEW, Uri.parse(String.valueOf(uri)));
startActivity(feedback1);
}
......@@ -183,7 +183,7 @@ public class AboutActivity extends AppCompatActivity {
FeedbackBtn2.setOnClickListener(new View.OnClickListener()
{
public void onClick(View arg0) {
Uri uri = Uri.parse(String.valueOf(Constants.URL_XMPP));
Uri uri = Uri.parse(Constants.URL_XMPP);
Intent feedback2 = new Intent(Intent.ACTION_VIEW, Uri.parse(String.valueOf(uri)));
startActivity(feedback2);
}
......@@ -195,7 +195,7 @@ public class AboutActivity extends AppCompatActivity {
fDroidBtn.setOnClickListener(new View.OnClickListener()
{
public void onClick(View arg0) {
Uri uri = Uri.parse(String.valueOf(Constants.URL_FDROID));
Uri uri = Uri.parse(Constants.URL_FDROID);
Intent fDroid = new Intent(Intent.ACTION_VIEW, Uri.parse(String.valueOf(uri)));
startActivity(fDroid);
}
......@@ -205,23 +205,23 @@ public class AboutActivity extends AppCompatActivity {
homeBtn.setOnClickListener(new View.OnClickListener()
{
public void onClick(View arg0) {
Uri uri = Uri.parse(String.valueOf(Constants.URL_DISROOT));
Uri uri = Uri.parse(Constants.URL_DISROOT);
Intent home = new Intent(Intent.ACTION_VIEW, Uri.parse(String.valueOf(uri)));
startActivity(home);
}
});
final TextView PackageName= rootView.findViewById(R.id.PackageName);
PackageName.setText("ID: " + APPLICATION_ID);
PackageName.setText(getString( R.string.id ) + " "+ APPLICATION_ID);
final TextView AppVersion= rootView.findViewById(R.id.AppVersion);
AppVersion.setText("Version: " + VERSION_NAME + "(" + VERSION_CODE + ")");
AppVersion.setText(getString( R.string.version ) + " " + VERSION_NAME + "(" + VERSION_CODE + ")");
final TextView AndroidVersion= rootView.findViewById(R.id.AndroidVersion);
AndroidVersion.setText("Android version: " + Build.VERSION.RELEASE);
AndroidVersion.setText(getString( R.string.androidVersion ) + " " + Build.VERSION.RELEASE);
final TextView Device;
Device = rootView.findViewById(R.id.Device);
Device.setText("Device name: " + Build.MANUFACTURER + Build.MODEL);
Device.setText(getString( R.string.deviceName ) + " " + Build.MANUFACTURER + Build.MODEL);
break;
case 3:
rootView = inflater.inflate(R.layout.fragment_about_license, container, false);
......@@ -231,7 +231,7 @@ public class AboutActivity extends AppCompatActivity {
licenseBtn.setOnClickListener(new View.OnClickListener()
{
public void onClick(View arg0) {
Uri uri = Uri.parse(String.valueOf(Constants.URL_LICENSE));
Uri uri = Uri.parse(Constants.URL_LICENSE);
Intent license = new Intent(Intent.ACTION_VIEW, Uri.parse(String.valueOf(uri)));
startActivity(license);
}
......@@ -241,7 +241,7 @@ public class AboutActivity extends AppCompatActivity {
disrootBtn.setOnClickListener(new View.OnClickListener()
{
public void onClick(View arg0) {
Uri uri = Uri.parse(String.valueOf(Constants.URL_DISROOT));
Uri uri = Uri.parse(Constants.URL_DISROOT);
Intent disroot = new Intent(Intent.ACTION_VIEW, Uri.parse(String.valueOf(uri)));
startActivity(disroot);
}
......@@ -251,11 +251,13 @@ public class AboutActivity extends AppCompatActivity {
dioBtn.setOnClickListener(new View.OnClickListener()
{
public void onClick(View arg0) {
Uri uri = Uri.parse(String.valueOf(Constants.URL_DIO));
Uri uri = Uri.parse(Constants.URL_DIO);
Intent dio = new Intent(Intent.ACTION_VIEW, Uri.parse(String.valueOf(uri)));
startActivity(dio);
}
});
final TextView htmlToTextView = rootView.findViewById(R.id.ThirdParty);// textview links clickable
htmlToTextView.setMovementMethod( LinkMovementMethod.getInstance());// textview links clickable
break;
}
return rootView;
......
/*
This file is part of the dandelion*.
dandelion* is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
dandelion* is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with the dandelion*.
If not, see <http://www.gnu.org/licenses/>.
*/
package org.disroot.disrootapp.ui;
import android.content.Context;
import android.support.v7.widget.AppCompatTextView;
import android.text.Html;
import android.text.SpannableString;
import android.text.util.Linkify;
import android.util.AttributeSet;
import android.util.Patterns;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* TextView, that renders HTML with highlited and clickable links and hashtags.
* Links are opened in a webbrowser.
* Hashtags open the MainActivity, load the new-post site of the selected pod and insert the
* hashtag into the post editor. See data/HashtagContentProvider.
*/
public class HtmlTextView extends AppCompatTextView {
public HtmlTextView(Context context) {
super(context);
init();
}
public HtmlTextView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public HtmlTextView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}
/**
* Linkify, format markdown and escape the displayed message.
*/
private void init() {
formatHtmlAndCustomTags();
}
private void formatHtmlAndCustomTags() {
setText(new SpannableString(Html.fromHtml(getText().toString())));
Linkify.TransformFilter filter = new Linkify.TransformFilter() {
public final String transformUrl(final Matcher match, String url) {
return match.group();
}
};
Pattern hashtagPattern = Pattern.compile("[#]+[A-Za-z0-9-_]+\\b");
String hashtagScheme = MainActivity.CONTENT_HASHTAG;
Linkify.addLinks(this, hashtagPattern, hashtagScheme, null, filter);
Pattern urlPattern = Patterns.WEB_URL;
Linkify.addLinks(this, urlPattern, null, null, filter);
}
}
\ No newline at end of file
......@@ -8,7 +8,6 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.Color;
......@@ -59,7 +58,6 @@ import android.widget.ProgressBar;
import android.widget.ScrollView;
import android.widget.Toast;
import org.disroot.disrootapp.R;
import org.disroot.disrootapp.StatusService;
import org.disroot.disrootapp.utils.Constants;
......@@ -74,39 +72,42 @@ import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import de.cketti.library.changelog.ChangeLog;
@SuppressWarnings("ALL")
public class MainActivity extends AppCompatActivity implements View.OnLongClickListener {
public class MainActivity extends AppCompatActivity implements View.OnLongClickListener,View.OnClickListener {
private static final String TAG = MainActivity.class.getSimpleName();
private WebView webView;
private DisWebChromeClient disWebChromeClient;
Button button;
SharedPreferences firstStart = null;//first start
SharedPreferences check = null;
private static final int INPUT_FILE_REQUEST_CODE = 1;//file upload
private static final int FILECHOOSER_RESULTCODE = 1;
String loadUrl;
WebChromeClient.FileChooserParams chooserParams;
ValueCallback<Uri[]> chooserPathUri;
Button button;
private Button MailBtn,CloudBtn,DiasporaBtn,ForumBtn,ChatBtn,PadBtn,CalcBtn,BinBtn,UploadBtn,SearxBtn,PollsBtn,BoardBtn,NotesBtn,UserBtn,StateBtn,HowToBtn,AboutBtn;//all buttons
private CookieManager cookieManager;
private WebView webView;
private DisWebChromeClient disWebChromeClient;
private ValueCallback<Uri> mUploadMessage;
private Uri mCapturedImageURI = null;
private ValueCallback<Uri[]> mFilePathCallback;
private String mCameraPhotoPath;
ValueCallback<Uri[]> chooserPathUri;
private ProgressBar progressBar;
private int progressStatus = 0;
private Handler handler = new Handler();
private Snackbar snackbarExitApp;
private FragmentManager fm;
public static final int REQUEST_ID_MULTIPLE_PERMISSIONS = 1;
WebView chooserWV;
WebChromeClient.FileChooserParams chooserParams;
public static final String CONTENT_HASHTAG = "content://org.disroot.disrootapp.ui.mainactivity/";
private CookieManager cookieManager;
private String mCameraPhotoPath;
private String k9 = "com.fsck.k9";
private String nc = "com.nextcloud.client";
private String Diaspora = "com.github.dfa.diaspora_android";
private String Conversations = "eu.siacs.conversations";
private String PixArt = "de.pixart.messenger";
private String Padland = "com.mikifus.padland";
private String NotesApp = "it.niedermann.owncloud.notes";
private String loadUrl;
private int progressStatus = 0;
private static final int REQUEST_ID_MULTIPLE_PERMISSIONS = 1;//file upload
private static final int INPUT_FILE_REQUEST_CODE = 1;//file upload
private static final int FILECHOOSER_RESULTCODE = 1;//file upload
private static final String TAG = MainActivity.class.getSimpleName();
@Override
public void onCreate(Bundle savedInstanceState) {
......@@ -115,14 +116,14 @@ public class MainActivity extends AppCompatActivity implements View.OnLongClickL
FrameLayout frameLayoutContainer = findViewById(R.id.framelayout_container);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
//ViewGroup viewLoading = (ViewGroup) findViewById(R.id.linearlayout_view_loading_container);
setupWebView(savedInstanceState, frameLayoutContainer);
//settings
firstStart = getSharedPreferences("org.disroot.disrootap", MODE_PRIVATE);//fisrt start
check = getSharedPreferences("org.disroot.disrootapp", MODE_PRIVATE);
// enables the activity icon as a 'home' button. required if "android:targetSdkVersion" > 14
//getActionBar().setHomeButtonEnabled(true);
final ScrollView dashboard = findViewById(R.id.dashboard);
//Status service
Intent intent = new Intent( MainActivity.this, StatusService.class);
startService(intent);
//progressbarLoading
progressBar = findViewById(R.id.progressbarLoading);
......@@ -183,505 +184,275 @@ public class MainActivity extends AppCompatActivity implements View.OnLongClickL
}
});
//Set buttons
// Locate the button in activity_main.xml
button = findViewById(R.id.MailBtn);//MailBtn
button.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
showMailInfo();
return true;
}
});
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
//first time tap check
if (firstStart.getBoolean("firsttap", true)){
showFirstTap();
firstStart.edit().putBoolean("firsttap", false).apply();
return;
}
String k9 = "com.fsck.k9";
Intent mail = getPackageManager().getLaunchIntentForPackage(k9);
if(mail == null) {
showMailDialog();
return;
}
else startActivity(mail);
}
});
// Link the button in activity_main.xml
MailBtn = findViewById( R.id.MailBtn );
CloudBtn = findViewById( R.id.CloudBtn );
DiasporaBtn = findViewById( R.id.DiasporaBtn );
ForumBtn = findViewById( R.id.ForumBtn );
ChatBtn = findViewById( R.id.ChatBtn );
PadBtn = findViewById( R.id.PadBtn );
CalcBtn = findViewById( R.id.CalcBtn );
BinBtn = findViewById( R.id.BinBtn );
UploadBtn = findViewById( R.id.UploadBtn );
SearxBtn = findViewById( R.id.SearxBtn );
PollsBtn = findViewById( R.id.PollsBtn );
BoardBtn = findViewById( R.id.BoardBtn );
NotesBtn = findViewById( R.id.NotesBtn );
UserBtn = findViewById( R.id.UserBtn );
StateBtn = findViewById( R.id.StateBtn );
HowToBtn = findViewById( R.id.HowToBtn );
AboutBtn = findViewById( R.id.AboutBtn );
//Set longclick buttons
MailBtn.setOnLongClickListener( this );
CloudBtn.setOnLongClickListener( this );
DiasporaBtn.setOnLongClickListener( this );
ForumBtn.setOnLongClickListener( this );
ChatBtn.setOnLongClickListener( this );
PadBtn.setOnLongClickListener( this );
CalcBtn.setOnLongClickListener( this );
BinBtn.setOnLongClickListener( this );
UploadBtn.setOnLongClickListener( this );
SearxBtn.setOnLongClickListener( this );
PollsBtn.setOnLongClickListener( this );
BoardBtn.setOnLongClickListener( this );
NotesBtn.setOnLongClickListener( this );
UserBtn.setOnLongClickListener( this );
StateBtn.setOnLongClickListener( this );
HowToBtn.setOnLongClickListener( this );
AboutBtn.setOnLongClickListener( this );
//set clickbuttons
MailBtn.setOnClickListener( this );
CloudBtn.setOnClickListener( this );
DiasporaBtn.setOnClickListener( this );
ForumBtn.setOnClickListener( this );
ChatBtn.setOnClickListener( this );
PadBtn.setOnClickListener( this );
CalcBtn.setOnClickListener( this );
BinBtn.setOnClickListener( this );
UploadBtn.setOnClickListener( this );
SearxBtn.setOnClickListener( this );
PollsBtn.setOnClickListener( this );
BoardBtn.setOnClickListener( this );
NotesBtn.setOnClickListener( this );
UserBtn.setOnClickListener( this );
StateBtn.setOnClickListener( this );
HowToBtn.setOnClickListener( this );
AboutBtn.setOnClickListener( this );
button = findViewById(R.id.CloudBtn);//CloudBtn
button.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
showCloudInfo();
return true;
}
});
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
//first time tap check