Browse Source

Merge branch 'develop' of https://github.com/ThmmyNoLife/mTHMMY into develop

pull/61/merge
Thodoris1999 6 years ago
parent
commit
3d7a7f9394
  1. 4
      app/build.gradle
  2. 7
      app/src/main/AndroidManifest.xml
  3. 2
      app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardActivity.java
  4. 55
      app/src/main/java/gr/thmmy/mthmmy/activities/settings/SettingsFragment.java
  5. 3
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java
  6. 1
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/TopicTaskResult.java
  7. 28
      app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java
  8. 48
      app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java
  9. 9
      app/src/main/java/gr/thmmy/mthmmy/services/NotificationService.java
  10. 2
      app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ParseHelpers.java
  11. 4
      app/src/main/java/gr/thmmy/mthmmy/viewmodel/TopicViewModel.java
  12. 10
      app/src/main/res/values/strings.xml
  13. 49
      app/src/main/res/xml/app_preferences.xml

4
app/build.gradle

@ -4,13 +4,13 @@ apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
android {
compileSdkVersion 27
compileSdkVersion 28
defaultConfig {
vectorDrawables.useSupportLibrary = true
applicationId "gr.thmmy.mthmmy"
minSdkVersion 19
targetSdkVersion 27
targetSdkVersion 28
versionCode 13
versionName "1.4.1"
archivesBaseName = "mTHMMY-v$versionName"

7
app/src/main/AndroidManifest.xml

@ -17,9 +17,10 @@
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<meta-data
android:name="firebase_crashlytics_collection_enabled"
android:value="false" />
<meta-data android:name="firebase_crashlytics_collection_enabled" android:value="false" />
<meta-data android:name="firebase_analytics_collection_enabled" android:value="false" />
<meta-data android:name="google_analytics_adid_collection_enabled" android:value="false" />
<activity
android:name=".activities.main.MainActivity"

2
app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardActivity.java

@ -22,8 +22,8 @@ import java.util.ArrayList;
import java.util.Objects;
import gr.thmmy.mthmmy.R;
import gr.thmmy.mthmmy.activities.create_content.CreateContentActivity;
import gr.thmmy.mthmmy.activities.LoginActivity;
import gr.thmmy.mthmmy.activities.create_content.CreateContentActivity;
import gr.thmmy.mthmmy.base.BaseActivity;
import gr.thmmy.mthmmy.model.Board;
import gr.thmmy.mthmmy.model.Bookmark;

55
app/src/main/java/gr/thmmy/mthmmy/activities/settings/SettingsFragment.java

@ -13,21 +13,27 @@ import android.support.v7.preference.ListPreference;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceFragmentCompat;
import android.view.View;
import android.widget.Toast;
import java.util.ArrayList;
import gr.thmmy.mthmmy.R;
import gr.thmmy.mthmmy.base.BaseApplication;
import timber.log.Timber;
public class SettingsFragment extends PreferenceFragmentCompat {
import static gr.thmmy.mthmmy.activities.settings.SettingsActivity.DEFAULT_HOME_TAB;
import static gr.thmmy.mthmmy.activities.settings.SettingsActivity.POSTING_APP_SIGNATURE_ENABLE_KEY;
import static gr.thmmy.mthmmy.activities.settings.SettingsActivity.UPLOADING_APP_SIGNATURE_ENABLE_KEY;
public class SettingsFragment extends PreferenceFragmentCompat implements SharedPreferences.OnSharedPreferenceChangeListener {
public static final String ARG_IS_LOGGED_IN = "selectedRingtoneKey";
//Preferences xml keys
private static final String DEFAULT_HOME_TAB = "pref_app_main_default_tab_key";
private static final String SELECTED_NOTIFICATIONS_SOUND = "pref_notifications_select_sound_key";
private static final String POSTING_CATEGORY = "pref_category_posting_key";
private static final String POSTING_APP_SIGNATURE_ENABLE = "pref_posting_app_signature_enable_key";
private static final String UPLOADING_CATEGORY = "pref_category_uploading_key";
private static final String UPLOADING_APP_SIGNATURE_ENABLE = "pref_uploading_app_signature_enable_key";
public static final String PRIVACY_CRASHLYTICS_ENABLE_KEY = "pref_privacy_crashlytics_enable_key";
public static final String PRIVACY_ANALYTICS_ENABLE_KEY = "pref_privacy_analytics_enable_key";
//SharedPreferences keys
private static final int REQUEST_CODE_ALERT_RINGTONE = 2;
@ -64,9 +70,20 @@ public class SettingsFragment extends PreferenceFragmentCompat {
super.onCreate(savedInstanceState);
Bundle args = getArguments();
if (args != null) {
if (args != null)
isLoggedIn = args.getBoolean(ARG_IS_LOGGED_IN, false);
}
@Override
public void onResume() {
super.onResume();
getPreferenceManager().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
}
@Override
public void onPause() {
super.onPause();
getPreferenceManager().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this);
}
@Override
@ -79,10 +96,10 @@ public class SettingsFragment extends PreferenceFragmentCompat {
public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
findPreference(POSTING_CATEGORY).setVisible(isLoggedIn);
findPreference(POSTING_APP_SIGNATURE_ENABLE).setVisible(isLoggedIn);
findPreference(POSTING_APP_SIGNATURE_ENABLE_KEY).setVisible(isLoggedIn);
findPreference(UPLOADING_CATEGORY).setVisible(isLoggedIn);
findPreference(UPLOADING_APP_SIGNATURE_ENABLE).setVisible(isLoggedIn);
findPreference(UPLOADING_APP_SIGNATURE_ENABLE_KEY).setVisible(isLoggedIn);
if (!isLoggedIn && defaultHomeTabEntries.contains("Unread")) {
defaultHomeTabEntries.remove("Unread");
@ -154,10 +171,10 @@ public class SettingsFragment extends PreferenceFragmentCompat {
this.isLoggedIn = isLoggedIn;
findPreference(POSTING_CATEGORY).setVisible(isLoggedIn);
findPreference(POSTING_APP_SIGNATURE_ENABLE).setVisible(isLoggedIn);
findPreference(POSTING_APP_SIGNATURE_ENABLE_KEY).setVisible(isLoggedIn);
findPreference(UPLOADING_CATEGORY).setVisible(isLoggedIn);
findPreference(UPLOADING_APP_SIGNATURE_ENABLE).setVisible(isLoggedIn);
findPreference(UPLOADING_APP_SIGNATURE_ENABLE_KEY).setVisible(isLoggedIn);
if (!isLoggedIn && defaultHomeTabEntries.contains("Unread")) {
defaultHomeTabEntries.remove("Unread");
@ -173,4 +190,24 @@ public class SettingsFragment extends PreferenceFragmentCompat {
tmpCs = defaultHomeTabValues.toArray(new CharSequence[defaultHomeTabValues.size()]);
((ListPreference) findPreference(DEFAULT_HOME_TAB)).setEntryValues(tmpCs);
}
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
boolean enabled;
if (key.equals(getString(R.string.pref_privacy_crashlytics_enable_key))) {
enabled = sharedPreferences.getBoolean(key, false);
if(enabled)
Timber.i("Crashlytics collection will be enabled after restarting.");
else
Timber.i("Crashlytics collection will be disabled after restarting.");
Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "This change will take effect once you restart the app.", Toast.LENGTH_SHORT).show();
} else if (key.equals(getString(R.string.pref_privacy_analytics_enable_key))) {
enabled = sharedPreferences.getBoolean(key, false);
BaseApplication.getInstance().firebaseAnalyticsCollection(enabled);
if(enabled)
Timber.i("Analytics collection enabled.");
else
Timber.i("Analytics collection disabled.");
}
}
}

3
app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java

@ -4,7 +4,6 @@ import android.annotation.SuppressLint;
import android.app.NotificationManager;
import android.arch.lifecycle.ViewModelProviders;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Rect;
import android.net.Uri;
@ -37,7 +36,6 @@ import android.widget.TextView;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.function.Consumer;
import gr.thmmy.mthmmy.R;
import gr.thmmy.mthmmy.activities.topic.tasks.EditTask;
@ -60,7 +58,6 @@ import gr.thmmy.mthmmy.viewmodel.TopicViewModel;
import me.zhanghai.android.materialprogressbar.MaterialProgressBar;
import timber.log.Timber;
import static gr.thmmy.mthmmy.activities.topic.Posting.replyStatus;
import static gr.thmmy.mthmmy.services.NotificationService.NEW_POST_TAG;
/**

1
app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/TopicTaskResult.java

@ -2,7 +2,6 @@ package gr.thmmy.mthmmy.activities.topic.tasks;
import java.util.ArrayList;
import gr.thmmy.mthmmy.model.Post;
import gr.thmmy.mthmmy.model.TopicItem;
public class TopicTaskResult {

28
app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java

@ -301,9 +301,7 @@ public abstract class BaseActivity extends AppCompatActivity {
.withSelectionListEnabledForSingleProfile(false)
.withHeaderBackground(R.color.primary)
.addProfiles(profileDrawerItem)
.withOnAccountHeaderListener(new AccountHeader.OnAccountHeaderListener() {
@Override
public boolean onProfileChanged(View view, IProfile profile, boolean currentProfile) {
.withOnAccountHeaderListener((view, profile, currentProfile) -> {
if (sessionManager.isLoggedIn()) {
Intent intent = new Intent(BaseActivity.this, ProfileActivity.class);
Bundle extras = new Bundle();
@ -317,10 +315,10 @@ public abstract class BaseActivity extends AppCompatActivity {
intent.setFlags(FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
return false;
}
} else
startLoginActivity();
return true;
}
})
.build();
@ -360,12 +358,8 @@ public abstract class BaseActivity extends AppCompatActivity {
}
} else if (drawerItem.equals(LOG_ID)) {
if (!sessionManager.isLoggedIn()) //When logged out or if user is guest
{
Intent intent = new Intent(BaseActivity.this, LoginActivity.class);
startActivity(intent);
finish();
overridePendingTransition(R.anim.push_right_in, R.anim.push_right_out);
} else
startLoginActivity();
else
new LogoutTask().execute();
} else if (drawerItem.equals(ABOUT_ID)) {
if (!(BaseActivity.this instanceof AboutActivity)) {
@ -533,9 +527,7 @@ public abstract class BaseActivity extends AppCompatActivity {
} else {
thisPageBookmarkImageButton.setImageResource(R.drawable.ic_bookmark_false_accent_24dp);
}
thisPageBookmarkImageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
thisPageBookmarkImageButton.setOnClickListener(view -> {
if (thisPageBookmark.matchExists(boardsBookmarked)) {
thisPageBookmarkImageButton.setImageResource(R.drawable.ic_bookmark_false_accent_24dp);
Toast.makeText(getBaseContext(), "Bookmark removed", Toast.LENGTH_SHORT).show();
@ -544,7 +536,6 @@ public abstract class BaseActivity extends AppCompatActivity {
Toast.makeText(getBaseContext(), "Bookmark added", Toast.LENGTH_SHORT).show();
}
toggleBoardToBookmarks(thisPageBookmark);
}
});
}
@ -743,4 +734,11 @@ public abstract class BaseActivity extends AppCompatActivity {
protected void setMainActivity(MainActivity mainActivity) {
this.mainActivity = mainActivity;
}
private void startLoginActivity(){
Intent intent = new Intent(BaseActivity.this, LoginActivity.class);
startActivity(intent);
finish();
overridePendingTransition(R.anim.push_right_in, R.anim.push_right_out);
}
}

48
app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java

@ -39,6 +39,8 @@ import okhttp3.OkHttpClient;
import okhttp3.Request;
import timber.log.Timber;
import static gr.thmmy.mthmmy.activities.settings.SettingsFragment.SETTINGS_SHARED_PREFS;
public class BaseApplication extends Application {
private static BaseApplication baseApplication; //BaseApplication singleton
@ -49,11 +51,10 @@ public class BaseApplication extends Application {
private OkHttpClient client;
private SessionManager sessionManager;
//Shared Preferences
private final String SHARED_PREFS_NAME = "ThmmySharedPrefs";
private final String SHARED_PREFS = "ThmmySharedPrefs";
//Display Metrics
private static float dpHeight, dpWidth;
private static float dpWidth;
public static BaseApplication getInstance() {
return baseApplication;
@ -64,22 +65,35 @@ public class BaseApplication extends Application {
super.onCreate();
baseApplication = this; //init singleton
// Initialize Timber
if (BuildConfig.DEBUG)
Timber.plant(new Timber.DebugTree());
else
Timber.plant(new CrashReportingTree());
//Shared Preferences
SharedPreferences sharedPrefs = getSharedPreferences(SHARED_PREFS, MODE_PRIVATE);
SharedPreferences settingsSharedPrefs = getSharedPreferences(SETTINGS_SHARED_PREFS, Context.MODE_PRIVATE);
// Set up Crashlytics, disabled for debug builds
if (settingsSharedPrefs.getBoolean(getString(R.string.pref_privacy_crashlytics_enable_key), false)) {
Crashlytics crashlyticsKit = new Crashlytics.Builder()
.core(new CrashlyticsCore.Builder().disabled(BuildConfig.DEBUG).build())
.build();
// Initialize Fabric with the debug-disabled crashlytics.
// Initialize Fabric with the debug-disabled Crashlytics.
Fabric.with(this, crashlyticsKit);
// Initialize timber
if (BuildConfig.DEBUG)
Timber.plant(new Timber.DebugTree());
else
Timber.plant(new CrashReportingTree());
Timber.i("Starting app with Crashlytics enabled.");
} else
Timber.i("Starting app with Crashlytics disabled.");
// Analytics init
firebaseAnalytics = FirebaseAnalytics.getInstance(this);
boolean enableAnalytics = settingsSharedPrefs.getBoolean(getString(R.string.pref_privacy_analytics_enable_key), false);
firebaseAnalytics.setAnalyticsCollectionEnabled(enableAnalytics);
if(enableAnalytics)
Timber.i("Starting app with Analytics enabled.");
else
Timber.i("Starting app with Analytics disabled.");
SharedPreferences sharedPrefs = getSharedPreferences(SHARED_PREFS_NAME, MODE_PRIVATE);
SharedPrefsCookiePersistor sharedPrefsCookiePersistor = new SharedPrefsCookiePersistor(getApplicationContext());
PersistentCookieJar cookieJar = new PersistentCookieJar(new SetCookieCache(), sharedPrefsCookiePersistor);
client = new OkHttpClient.Builder()
@ -137,7 +151,6 @@ public class BaseApplication extends Application {
});
DisplayMetrics displayMetrics = getApplicationContext().getResources().getDisplayMetrics();
dpHeight = displayMetrics.heightPixels / displayMetrics.density;
dpWidth = displayMetrics.widthPixels / displayMetrics.density;
}
@ -145,8 +158,13 @@ public class BaseApplication extends Application {
firebaseAnalytics.logEvent(event, params);
}
//Getters
public void firebaseAnalyticsCollection(boolean enabled) {
firebaseAnalytics.setAnalyticsCollectionEnabled(enabled);
if(!enabled)
firebaseAnalytics.resetAnalyticsData();
}
//Getters
public OkHttpClient getClient() {
return client;
}
@ -155,10 +173,6 @@ public class BaseApplication extends Application {
return sessionManager;
}
public float getDpHeight() {
return dpHeight;
}
public float getDpWidth() {
return dpWidth;
}

9
app/src/main/java/gr/thmmy/mthmmy/services/NotificationService.java

@ -226,4 +226,13 @@ public class NotificationService extends FirebaseMessagingService {
}
/**
* Called if InstanceID token is updated. Note that this is called when the InstanceID token
* is initially generated so this is where you would retrieve the token.
*/
@Override
public void onNewToken(String s) {
super.onNewToken(s);
Timber.i("InstanceID token updated (onNewToken)");
}
}

2
app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ParseHelpers.java

@ -8,8 +8,6 @@ import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import timber.log.Timber;
/**
* This class consists exclusively of static classes (enums) and methods (excluding methods of inner
* classes). It can be used to resolve a page's language and state or fix embedded videos html code.

4
app/src/main/java/gr/thmmy/mthmmy/viewmodel/TopicViewModel.java

@ -10,12 +10,10 @@ import android.widget.LinearLayout;
import android.widget.RadioGroup;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.TimerTask;
import gr.thmmy.mthmmy.activities.settings.SettingsActivity;
import gr.thmmy.mthmmy.activities.topic.tasks.EditTask;
import gr.thmmy.mthmmy.activities.topic.tasks.DeleteTask;
import gr.thmmy.mthmmy.activities.topic.tasks.EditTask;
import gr.thmmy.mthmmy.activities.topic.tasks.PrepareForEditResult;
import gr.thmmy.mthmmy.activities.topic.tasks.PrepareForEditTask;
import gr.thmmy.mthmmy.activities.topic.tasks.PrepareForReply;

10
app/src/main/res/values/strings.xml

@ -152,8 +152,6 @@
<string name="pref_app_main_default_tab_dialog_title">Default home tab</string>
<string name="pref_category_notifications">Notifications</string>
<!--<string name="pref_title_notifications_enable">New posts notification</string>
<string name="pref_summary_notifications_enable">Toggle notifications state</string>-->
<string name="pref_title_notification_vibration_enable">Vibration</string>
<string name="pref_title_notification_led_enable">Notifications led</string>
<string name="pref_summary_notification_led_enable">Enables/disables the notifications led (if the device has one)</string>
@ -168,6 +166,14 @@
<string name="pref_title_uploading_app_signature_enable">App signature</string>
<string name="pref_summary_uploading_app_signature_enable">Appends an \"uploaded from mTHMMY\" message to the descriptions of your uploads</string>
<string name="pref_category_privacy">Privacy</string>
<string name="pref_privacy_crashlytics_enable_key">pref_privacy_crashlytics_enable_key</string>
<string name="pref_title_privacy_crashlytics_enable">Crash data reports</string>
<string name="pref_summary_privacy_crashlytics_enable">Automatically send us anonymized reports of errors and crashes</string>
<string name="pref_privacy_analytics_enable_key">pref_privacy_analytics_enable_key</string>
<string name="pref_title_privacy_analytics_enable">Analytics data reports</string>
<string name="pref_summary_privacy_analytics_enable">Automatically send us anonymized data for analytical purposes</string>
<!-- EditorView -->
<string name="black">Black</string>
<string name="red">Red</string>

49
app/src/main/res/xml/app_preferences.xml

@ -2,66 +2,65 @@
<android.support.v7.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<android.support.v7.preference.PreferenceCategory android:title="@string/pref_category_app">
<android.support.v7.preference.ListPreference
android:defaultValue="0"
android:dialogTitle="@string/pref_app_main_default_tab_dialog_title"
android:entries="@array/pref_app_main_default_tab_entries"
android:entryValues="@array/pref_app_main_default_tab_values"
android:key="pref_app_main_default_tab_key"
android:summary="@string/pref_summary_app_main_default_tab"
android:title="@string/pref_title_app_main_default_tab" />
android:title="@string/pref_title_app_main_default_tab"
android:summary="@string/pref_summary_app_main_default_tab" />
</android.support.v7.preference.PreferenceCategory>
<android.support.v7.preference.PreferenceCategory android:title="@string/pref_category_notifications">
<!--<android.support.v7.preference.SwitchPreferenceCompat
android:defaultValue="true"
android:key="pref_notifications_enable_key"
android:summary="@string/pref_summary_notifications_enable"
android:title="@string/pref_title_notifications_enable" />-->
<android.support.v7.preference.SwitchPreferenceCompat
android:defaultValue="true"
android:key="pref_notification_vibration_enable_key"
android:title="@string/pref_title_notification_vibration_enable" />
<android.support.v7.preference.SwitchPreferenceCompat
android:defaultValue="true"
android:key="pref_notification_led_enable_key"
android:summary="@string/pref_summary_notification_led_enable"
android:title="@string/pref_title_notification_led_enable" />
android:title="@string/pref_title_notification_led_enable"
android:summary="@string/pref_summary_notification_led_enable" />
<Preference
android:key="pref_notifications_select_sound_key"
android:summary="@string/pref_summary_notifications_sound"
android:title="@string/pref_title_notifications_sound" />
android:title="@string/pref_title_notifications_sound"
android:summary="@string/pref_summary_notifications_sound" />
</android.support.v7.preference.PreferenceCategory>
<android.support.v7.preference.PreferenceCategory
android:key="pref_category_posting_key"
android:title="@string/pref_category_posting">
<android.support.v7.preference.SwitchPreferenceCompat
android:defaultValue="true"
android:key="pref_posting_app_signature_enable_key"
android:summary="@string/pref_summary_posting_app_signature_enable"
android:title="@string/pref_title_posting_app_signature_enable" />
android:title="@string/pref_title_posting_app_signature_enable"
android:summary="@string/pref_summary_posting_app_signature_enable" />
</android.support.v7.preference.PreferenceCategory>
<android.support.v7.preference.PreferenceCategory
android:key="pref_category_uploading_key"
android:title="@string/pref_category_uploading">
<android.support.v7.preference.SwitchPreferenceCompat
android:defaultValue="true"
android:key="pref_uploading_app_signature_enable_key"
android:summary="@string/pref_summary_uploading_app_signature_enable"
android:title="@string/pref_title_uploading_app_signature_enable" />
android:title="@string/pref_title_uploading_app_signature_enable"
android:summary="@string/pref_summary_uploading_app_signature_enable" />
</android.support.v7.preference.PreferenceCategory>
<android.support.v7.preference.PreferenceCategory
android:key="pref_category_privacy_key"
android:title="@string/pref_category_privacy">
<android.support.v7.preference.SwitchPreferenceCompat
android:defaultValue="false"
android:key="@string/pref_privacy_crashlytics_enable_key"
android:title="@string/pref_title_privacy_crashlytics_enable"
android:summary="@string/pref_summary_privacy_crashlytics_enable" />
<android.support.v7.preference.SwitchPreferenceCompat
android:defaultValue="false"
android:key="@string/pref_privacy_analytics_enable_key"
android:title="@string/pref_title_privacy_analytics_enable"
android:summary="@string/pref_summary_privacy_analytics_enable" />
</android.support.v7.preference.PreferenceCategory>
</android.support.v7.preference.PreferenceScreen>
Loading…
Cancel
Save