Browse Source

Merge remote-tracking branch 'upstream/develop' into develop

pull/24/head
Thodoris1999 7 years ago
parent
commit
678c1db689
  1. 2
      app/build.gradle
  2. 9
      app/src/main/AndroidManifest.xml
  3. 3
      app/src/main/java/gr/thmmy/mthmmy/activities/LoginActivity.java
  4. 39
      app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarkActivity.java
  5. 3
      app/src/main/java/gr/thmmy/mthmmy/activities/main/MainActivity.java
  6. 44
      app/src/main/java/gr/thmmy/mthmmy/activities/settings/SettingsActivity.java
  7. 82
      app/src/main/java/gr/thmmy/mthmmy/activities/settings/SettingsFragment.java
  8. 39
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java
  9. 71
      app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java
  10. 87
      app/src/main/java/gr/thmmy/mthmmy/services/NotificationService.java
  11. BIN
      app/src/main/res/drawable-hdpi/ic_notification.png
  12. BIN
      app/src/main/res/drawable-mdpi/ic_notification.png
  13. BIN
      app/src/main/res/drawable-xhdpi/ic_notification.png
  14. BIN
      app/src/main/res/drawable-xxhdpi/ic_notification.png
  15. 4
      app/src/main/res/layout/activity_bookmark.xml
  16. 33
      app/src/main/res/layout/activity_settings.xml
  17. 1
      app/src/main/res/values-v21/styles.xml
  18. 21
      app/src/main/res/values/strings.xml
  19. 1
      app/src/main/res/values/styles.xml
  20. 35
      app/src/main/res/xml/app_preferences.xml

2
app/build.gradle

@ -31,6 +31,8 @@ dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar']) implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1' implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:design:27.1.1' implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support:preference-v7:27.1.1'
implementation 'com.android.support:preference-v14:27.1.1'
implementation 'com.android.support:support-v4:27.1.1' implementation 'com.android.support:support-v4:27.1.1'
implementation 'com.android.support:cardview-v7:27.1.1' implementation 'com.android.support:cardview-v7:27.1.1'
implementation 'com.android.support:recyclerview-v7:27.1.1' implementation 'com.android.support:recyclerview-v7:27.1.1'

9
app/src/main/AndroidManifest.xml

@ -105,6 +105,15 @@
android:name="android.support.PARENT_ACTIVITY" android:name="android.support.PARENT_ACTIVITY"
android:value=".activities.main.MainActivity" /> android:value=".activities.main.MainActivity" />
</activity> </activity>
<activity
android:name=".activities.settings.SettingsActivity"
android:parentActivityName=".activities.main.MainActivity"
android:launchMode="singleInstance"
android:theme="@style/AppTheme.NoActionBar">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".activities.main.MainActivity" />
</activity>
<provider <provider
android:name="android.support.v4.content.FileProvider" android:name="android.support.v4.content.FileProvider"

3
app/src/main/java/gr/thmmy/mthmmy/activities/LoginActivity.java

@ -3,6 +3,7 @@ package gr.thmmy.mthmmy.activities;
import android.content.Intent; import android.content.Intent;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.preference.PreferenceManager;
import android.support.v7.widget.AppCompatButton; import android.support.v7.widget.AppCompatButton;
import android.view.View; import android.view.View;
import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodManager;
@ -42,6 +43,8 @@ public class LoginActivity extends BaseActivity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login); setContentView(R.layout.activity_login);
PreferenceManager.setDefaultValues(this, R.xml.app_preferences, false);
//Variables initialization //Variables initialization
inputUsername = findViewById(R.id.username); inputUsername = findViewById(R.id.username);
inputPassword = findViewById(R.id.password); inputPassword = findViewById(R.id.password);

39
app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarkActivity.java

@ -63,27 +63,30 @@ public class BookmarkActivity extends BaseActivity {
super.onResume(); super.onResume();
} }
public boolean onTopicInteractionListener(String interactionType, Bookmark bookmarkedTopic){ public boolean onTopicInteractionListener(String interactionType, Bookmark bookmarkedTopic) {
if (interactionType.equals(TopicBookmarksFragment.INTERACTION_CLICK_TOPIC_BOOKMARK)){ switch (interactionType) {
Intent intent = new Intent(BookmarkActivity.this, TopicActivity.class); case TopicBookmarksFragment.INTERACTION_CLICK_TOPIC_BOOKMARK:
Bundle extras = new Bundle(); Intent intent = new Intent(BookmarkActivity.this, TopicActivity.class);
extras.putString(BUNDLE_TOPIC_URL, "https://www.thmmy.gr/smf/index.php?topic=" Bundle extras = new Bundle();
+ bookmarkedTopic.getId() + "." + 2147483647); extras.putString(BUNDLE_TOPIC_URL, "https://www.thmmy.gr/smf/index.php?topic="
extras.putString(BUNDLE_TOPIC_TITLE, bookmarkedTopic.getTitle()); + bookmarkedTopic.getId() + "." + 2147483647);
intent.putExtras(extras); extras.putString(BUNDLE_TOPIC_TITLE, bookmarkedTopic.getTitle());
startActivity(intent); intent.putExtras(extras);
finish(); startActivity(intent);
} else if (interactionType.equals(TopicBookmarksFragment.INTERACTION_TOGGLE_TOPIC_NOTIFICATION)) { finish();
return toggleNotification(bookmarkedTopic); break;
} else if (interactionType.equals(TopicBookmarksFragment.INTERACTION_REMOVE_TOPIC_BOOKMARK)){ case TopicBookmarksFragment.INTERACTION_TOGGLE_TOPIC_NOTIFICATION:
removeBookmark(bookmarkedTopic); return toggleNotification(bookmarkedTopic);
Toast.makeText(BookmarkActivity.this, "Bookmark removed", Toast.LENGTH_SHORT).show(); case TopicBookmarksFragment.INTERACTION_REMOVE_TOPIC_BOOKMARK:
removeBookmark(bookmarkedTopic);
Toast.makeText(BookmarkActivity.this, "Bookmark removed", Toast.LENGTH_SHORT).show();
break;
} }
return true; return true;
} }
public void onBoardInteractionListener(String interactionType, Bookmark bookmarkedBoard){ public void onBoardInteractionListener(String interactionType, Bookmark bookmarkedBoard) {
if (interactionType.equals(BoardBookmarksFragment.INTERACTION_CLICK_BOARD_BOOKMARK)){ if (interactionType.equals(BoardBookmarksFragment.INTERACTION_CLICK_BOARD_BOOKMARK)) {
Intent intent = new Intent(BookmarkActivity.this, BoardActivity.class); Intent intent = new Intent(BookmarkActivity.this, BoardActivity.class);
Bundle extras = new Bundle(); Bundle extras = new Bundle();
extras.putString(BUNDLE_BOARD_URL, "https://www.thmmy.gr/smf/index.php?board=" extras.putString(BUNDLE_BOARD_URL, "https://www.thmmy.gr/smf/index.php?board="
@ -92,7 +95,7 @@ public class BookmarkActivity extends BaseActivity {
intent.putExtras(extras); intent.putExtras(extras);
startActivity(intent); startActivity(intent);
finish(); finish();
} else if (interactionType.equals(BoardBookmarksFragment.INTERACTION_REMOVE_BOARD_BOOKMARK)){ } else if (interactionType.equals(BoardBookmarksFragment.INTERACTION_REMOVE_BOARD_BOOKMARK)) {
removeBookmark(bookmarkedBoard); removeBookmark(bookmarkedBoard);
Toast.makeText(BookmarkActivity.this, "Bookmark removed", Toast.LENGTH_SHORT).show(); Toast.makeText(BookmarkActivity.this, "Bookmark removed", Toast.LENGTH_SHORT).show();
} }

3
app/src/main/java/gr/thmmy/mthmmy/activities/main/MainActivity.java

@ -8,6 +8,7 @@ import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager; import android.support.v4.view.ViewPager;
import android.support.v7.preference.PreferenceManager;
import android.widget.Toast; import android.widget.Toast;
import java.util.ArrayList; import java.util.ArrayList;
@ -53,6 +54,8 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF
redirectToActivityFromIntent(intentFilter); redirectToActivityFromIntent(intentFilter);
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
PreferenceManager.setDefaultValues(this, R.xml.app_preferences, false);
if (sessionManager.isLoginScreenDefault()) { if (sessionManager.isLoginScreenDefault()) {
//Go to login //Go to login
Intent intent = new Intent(MainActivity.this, LoginActivity.class); Intent intent = new Intent(MainActivity.this, LoginActivity.class);

44
app/src/main/java/gr/thmmy/mthmmy/activities/settings/SettingsActivity.java

@ -0,0 +1,44 @@
package gr.thmmy.mthmmy.activities.settings;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import gr.thmmy.mthmmy.R;
import gr.thmmy.mthmmy.base.BaseActivity;
public class SettingsActivity extends BaseActivity {
public static final String NOTIFICATION_VIBRATION_KEY = "pref_notification_vibration_enable_key";
public static final String APP_SIGNATURE_ENABLE_KEY = "pref_posting_app_signature_enable_key";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);
//Initialize toolbar
toolbar = findViewById(R.id.toolbar);
toolbar.setTitle("Settings");
setSupportActionBar(toolbar);
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
createDrawer();
drawer.setSelection(SETTINGS_ID);
if (savedInstanceState == null) {
Fragment preferenceFragment = new SettingsFragment();
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.add(R.id.pref_container, preferenceFragment);
fragmentTransaction.commit();
}
}
@Override
protected void onResume() {
drawer.setSelection(SETTINGS_ID);
super.onResume();
}
}

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

@ -0,0 +1,82 @@
package gr.thmmy.mthmmy.activities.settings;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Settings;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceFragmentCompat;
import android.util.Log;
import gr.thmmy.mthmmy.R;
public class SettingsFragment extends PreferenceFragmentCompat {
private static final int REQUEST_CODE_ALERT_RINGTONE = 2;
public static final String SETTINGS_SHARED_PREFS = "settingsSharedPrefs";
public static final String SELECTED_RINGTONE = "selectedRingtoneKey";
private static final String SELECTED_NOTIFICATIONS_SOUND = "pref_notifications_select_sound_key";
private static final String SILENT_SELECTED = "STFU";
private SharedPreferences settingsFile;
@Override
public void onCreatePreferences(Bundle bundle, String s) {
// Load the Preferences from the XML file
addPreferencesFromResource(R.xml.app_preferences);
}
@Override
public boolean onPreferenceTreeClick(Preference preference) {
if (preference.getKey().equals(SELECTED_NOTIFICATIONS_SOUND)) {
Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI, Settings.System.DEFAULT_NOTIFICATION_URI);
Activity activity = this.getActivity();
settingsFile = activity != null
? activity.getSharedPreferences(SETTINGS_SHARED_PREFS, Context.MODE_PRIVATE)
: null;
String existingValue = settingsFile != null
? settingsFile.getString(SELECTED_RINGTONE, null)
: null;
if (existingValue != null) {
if (existingValue.equals(SILENT_SELECTED)) {
//Selects "Silent"
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, (Uri) null);
} else {
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, Uri.parse(existingValue));
}
} else {
//No ringtone has been selected, set to the default
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, Settings.System.DEFAULT_NOTIFICATION_URI);
}
startActivityForResult(intent, REQUEST_CODE_ALERT_RINGTONE);
return true;
} else {
return super.onPreferenceTreeClick(preference);
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_CODE_ALERT_RINGTONE && data != null) {
Uri ringtone = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
SharedPreferences.Editor editor = settingsFile.edit();
if (ringtone != null) {
editor.putString(SELECTED_RINGTONE, ringtone.toString()).apply();
} else {
// "Silent" was selected
editor.putString(SELECTED_RINGTONE, SILENT_SELECTED).apply();
}
} else {
super.onActivityResult(requestCode, resultCode, data);
}
}
}

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

@ -4,6 +4,7 @@ import android.annotation.SuppressLint;
import android.app.NotificationManager; import android.app.NotificationManager;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Rect; import android.graphics.Rect;
import android.net.Uri; import android.net.Uri;
import android.os.AsyncTask; import android.os.AsyncTask;
@ -12,6 +13,7 @@ import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.support.design.widget.FloatingActionButton; import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.support.v7.preference.PreferenceManager;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.text.Html; import android.text.Html;
import android.text.SpannableStringBuilder; import android.text.SpannableStringBuilder;
@ -44,6 +46,7 @@ import java.util.Objects;
import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.R;
import gr.thmmy.mthmmy.activities.board.BoardActivity; import gr.thmmy.mthmmy.activities.board.BoardActivity;
import gr.thmmy.mthmmy.activities.profile.ProfileActivity; import gr.thmmy.mthmmy.activities.profile.ProfileActivity;
import gr.thmmy.mthmmy.activities.settings.SettingsActivity;
import gr.thmmy.mthmmy.base.BaseActivity; import gr.thmmy.mthmmy.base.BaseActivity;
import gr.thmmy.mthmmy.model.Bookmark; import gr.thmmy.mthmmy.model.Bookmark;
import gr.thmmy.mthmmy.model.Post; import gr.thmmy.mthmmy.model.Post;
@ -184,6 +187,7 @@ public class TopicActivity extends BaseActivity {
* navigation bar occurs * navigation bar occurs
*/ */
private Integer pageRequestValue; private Integer pageRequestValue;
//Bottom navigation bar graphics related //Bottom navigation bar graphics related
private LinearLayout bottomNavBar; private LinearLayout bottomNavBar;
private ImageButton firstPage; private ImageButton firstPage;
@ -191,10 +195,12 @@ public class TopicActivity extends BaseActivity {
private TextView pageIndicator; private TextView pageIndicator;
private ImageButton nextPage; private ImageButton nextPage;
private ImageButton lastPage; private ImageButton lastPage;
//Topic's info related //Topic's info related
private SpannableStringBuilder topicTreeAndMods = new SpannableStringBuilder("Loading..."), private SpannableStringBuilder topicTreeAndMods = new SpannableStringBuilder("Loading..."),
topicViewers = new SpannableStringBuilder("Loading..."); topicViewers = new SpannableStringBuilder("Loading...");
boolean includeAppSignaturePreference = true;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -214,6 +220,11 @@ public class TopicActivity extends BaseActivity {
topicPageUrl = ThmmyPage.sanitizeTopicUrl(topicPageUrl); topicPageUrl = ThmmyPage.sanitizeTopicUrl(topicPageUrl);
if (sessionManager.isLoggedIn()) {
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
includeAppSignaturePreference = sharedPrefs.getBoolean(SettingsActivity.APP_SIGNATURE_ENABLE_KEY, true);
}
thisPageBookmark = new Bookmark(topicTitle, ThmmyPage.getTopicId(topicPageUrl), true); thisPageBookmark = new Bookmark(topicTitle, ThmmyPage.getTopicId(topicPageUrl), true);
//Initializes graphics //Initializes graphics
@ -321,7 +332,7 @@ public class TopicActivity extends BaseActivity {
dialog.show(); dialog.show();
return true; return true;
case R.id.menu_share: case R.id.menu_share:
Intent sendIntent = new Intent(android.content.Intent.ACTION_SEND); Intent sendIntent = new Intent(android.content.Intent.ACTION_SEND);
sendIntent.setType("text/plain"); sendIntent.setType("text/plain");
sendIntent.putExtra(android.content.Intent.EXTRA_TEXT, topicPageUrl); sendIntent.putExtra(android.content.Intent.EXTRA_TEXT, topicPageUrl);
startActivity(Intent.createChooser(sendIntent, "Share via")); startActivity(Intent.createChooser(sendIntent, "Share via"));
@ -336,9 +347,7 @@ public class TopicActivity extends BaseActivity {
if (drawer.isDrawerOpen()) { if (drawer.isDrawerOpen()) {
drawer.closeDrawer(); drawer.closeDrawer();
return; return;
} } else if (postsList != null && postsList.size() > 0 && postsList.get(postsList.size() - 1) == null) {
else if(postsList!=null && postsList.size()>0 && postsList.get(postsList.size()-1)==null)
{
postsList.remove(postsList.size() - 1); postsList.remove(postsList.size() - 1);
topicAdapter.notifyItemRemoved(postsList.size()); topicAdapter.notifyItemRemoved(postsList.size());
topicAdapter.setBackButtonHidden(); topicAdapter.setBackButtonHidden();
@ -356,6 +365,11 @@ public class TopicActivity extends BaseActivity {
super.onResume(); super.onResume();
refreshTopicBookmark(); refreshTopicBookmark();
drawer.setSelection(-1); drawer.setSelection(-1);
if (sessionManager.isLoggedIn()) {
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
includeAppSignaturePreference = sharedPrefs.getBoolean(SettingsActivity.APP_SIGNATURE_ENABLE_KEY, true);
}
} }
@Override @Override
@ -548,7 +562,8 @@ public class TopicActivity extends BaseActivity {
} }
} }
//------------------------------------BOTTOM NAV BAR METHODS END------------------------------------
//------------------------------------BOTTOM NAV BAR METHODS END------------------------------------
private enum ResultCode { private enum ResultCode {
SUCCESS, NETWORK_ERROR, PARSING_ERROR, OTHER_ERROR, SAME_PAGE, UNAUTHORIZED SUCCESS, NETWORK_ERROR, PARSING_ERROR, OTHER_ERROR, SAME_PAGE, UNAUTHORIZED
} }
@ -632,7 +647,7 @@ public class TopicActivity extends BaseActivity {
Timber.i(e, "IO Exception"); Timber.i(e, "IO Exception");
return ResultCode.NETWORK_ERROR; return ResultCode.NETWORK_ERROR;
} catch (ParseException e) { } catch (ParseException e) {
if(isUnauthorized(document)) if (isUnauthorized(document))
return ResultCode.UNAUTHORIZED; return ResultCode.UNAUTHORIZED;
Timber.e(e, "Parsing Error"); Timber.e(e, "Parsing Error");
return ResultCode.PARSING_ERROR; return ResultCode.PARSING_ERROR;
@ -673,9 +688,9 @@ public class TopicActivity extends BaseActivity {
pageIndicator.setText(String.valueOf(thisPage) + "/" + String.valueOf(numberOfPages)); pageIndicator.setText(String.valueOf(thisPage) + "/" + String.valueOf(numberOfPages));
pageRequestValue = thisPage; pageRequestValue = thisPage;
if(thisPage==numberOfPages){ if (thisPage == numberOfPages) {
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
if(notificationManager!=null) if (notificationManager != null)
notificationManager.cancel(NEW_POST_TAG, loadedPageTopicId); notificationManager.cancel(NEW_POST_TAG, loadedPageTopicId);
} }
@ -702,7 +717,7 @@ public class TopicActivity extends BaseActivity {
} }
} }
private void stopLoading(){ private void stopLoading() {
progressBar.setVisibility(ProgressBar.INVISIBLE); progressBar.setVisibility(ProgressBar.INVISIBLE);
if (replyPageUrl == null) { if (replyPageUrl == null) {
replyFAB.hide(); replyFAB.hide();
@ -718,7 +733,7 @@ public class TopicActivity extends BaseActivity {
* @param topic {@link Document} object containing this topic's source code * @param topic {@link Document} object containing this topic's source code
* @see org.jsoup.Jsoup Jsoup * @see org.jsoup.Jsoup Jsoup
*/ */
private ArrayList<Post> parse(Document topic) throws ParseException{ private ArrayList<Post> parse(Document topic) throws ParseException {
try { try {
ParseHelpers.Language language = ParseHelpers.Language.getLanguage(topic); ParseHelpers.Language language = ParseHelpers.Language.getLanguage(topic);
@ -898,7 +913,9 @@ public class TopicActivity extends BaseActivity {
@Override @Override
protected Boolean doInBackground(String... args) { protected Boolean doInBackground(String... args) {
final String sentFrommTHMMY = "\n[right][size=7pt][i]sent from [url=https://play.google.com/store/apps/details?id=gr.thmmy.mthmmy]mTHMMY [/url][/i][/size][/right]"; final String sentFrommTHMMY = includeAppSignaturePreference
? "\n[right][size=7pt][i]sent from [url=https://play.google.com/store/apps/details?id=gr.thmmy.mthmmy]mTHMMY [/url][/i][/size][/right]"
: "";
RequestBody postBody = new MultipartBody.Builder() RequestBody postBody = new MultipartBody.Builder()
.setType(MultipartBody.FORM) .setType(MultipartBody.FORM)
.addFormDataPart("message", args[1] + sentFrommTHMMY) .addFormDataPart("message", args[1] + sentFrommTHMMY)

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

@ -47,6 +47,7 @@ import gr.thmmy.mthmmy.activities.LoginActivity;
import gr.thmmy.mthmmy.activities.downloads.DownloadsActivity; import gr.thmmy.mthmmy.activities.downloads.DownloadsActivity;
import gr.thmmy.mthmmy.activities.main.MainActivity; import gr.thmmy.mthmmy.activities.main.MainActivity;
import gr.thmmy.mthmmy.activities.profile.ProfileActivity; import gr.thmmy.mthmmy.activities.profile.ProfileActivity;
import gr.thmmy.mthmmy.activities.settings.SettingsActivity;
import gr.thmmy.mthmmy.model.Bookmark; import gr.thmmy.mthmmy.model.Bookmark;
import gr.thmmy.mthmmy.model.ThmmyFile; import gr.thmmy.mthmmy.model.ThmmyFile;
import gr.thmmy.mthmmy.services.DownloadHelper; import gr.thmmy.mthmmy.services.DownloadHelper;
@ -147,10 +148,11 @@ public abstract class BaseActivity extends AppCompatActivity {
protected static final int BOOKMARKS_ID = 2; protected static final int BOOKMARKS_ID = 2;
protected static final int LOG_ID = 3; protected static final int LOG_ID = 3;
protected static final int ABOUT_ID = 4; protected static final int ABOUT_ID = 4;
protected static final int SETTINGS_ID = 5;
private AccountHeader accountHeader; private AccountHeader accountHeader;
private ProfileDrawerItem profileDrawerItem; private ProfileDrawerItem profileDrawerItem;
private PrimaryDrawerItem downloadsItem, loginLogoutItem; private PrimaryDrawerItem downloadsItem, settingsItem, loginLogoutItem;
private IconicsDrawable loginIcon, logoutIcon; private IconicsDrawable loginIcon, logoutIcon;
/** /**
@ -162,9 +164,8 @@ public abstract class BaseActivity extends AppCompatActivity {
final int selectedSecondaryColor = ContextCompat.getColor(this, R.color.accent); final int selectedSecondaryColor = ContextCompat.getColor(this, R.color.accent);
PrimaryDrawerItem homeItem, bookmarksItem, aboutItem; PrimaryDrawerItem homeItem, bookmarksItem, aboutItem;
IconicsDrawable homeIcon, homeIconSelected, downloadsIcon, downloadsIconSelected, IconicsDrawable homeIcon, homeIconSelected, downloadsIcon, downloadsIconSelected, settingsIcon,
bookmarksIcon, bookmarksIconSelected, aboutIcon, settingsIconSelected, bookmarksIcon, bookmarksIconSelected, aboutIcon, aboutIconSelected;
aboutIconSelected;
//Drawer Icons //Drawer Icons
homeIcon = new IconicsDrawable(this) homeIcon = new IconicsDrawable(this)
@ -188,6 +189,14 @@ public abstract class BaseActivity extends AppCompatActivity {
.color(primaryColor); .color(primaryColor);
downloadsIconSelected = new IconicsDrawable(this) downloadsIconSelected = new IconicsDrawable(this)
.icon(GoogleMaterial.Icon.gmd_settings)
.color(selectedSecondaryColor);
settingsIcon = new IconicsDrawable(this)
.icon(GoogleMaterial.Icon.gmd_settings)
.color(primaryColor);
settingsIconSelected = new IconicsDrawable(this)
.icon(GoogleMaterial.Icon.gmd_file_download) .icon(GoogleMaterial.Icon.gmd_file_download)
.color(selectedSecondaryColor); .color(selectedSecondaryColor);
@ -243,6 +252,15 @@ public abstract class BaseActivity extends AppCompatActivity {
.withIcon(loginIcon) .withIcon(loginIcon)
.withSelectable(false); .withSelectable(false);
settingsItem = new PrimaryDrawerItem()
.withTextColor(primaryColor)
.withSelectedColor(selectedPrimaryColor)
.withSelectedTextColor(selectedSecondaryColor)
.withIdentifier(SETTINGS_ID)
.withName(R.string.settings)
.withIcon(settingsIcon)
.withSelectedIcon(settingsIconSelected);
bookmarksItem = new PrimaryDrawerItem() bookmarksItem = new PrimaryDrawerItem()
.withTextColor(primaryColor) .withTextColor(primaryColor)
.withSelectedColor(selectedPrimaryColor) .withSelectedColor(selectedPrimaryColor)
@ -337,7 +355,11 @@ public abstract class BaseActivity extends AppCompatActivity {
Intent i = new Intent(BaseActivity.this, AboutActivity.class); Intent i = new Intent(BaseActivity.this, AboutActivity.class);
startActivity(i); startActivity(i);
} }
} else if (drawerItem.equals(SETTINGS_ID)) {
if (!(BaseActivity.this instanceof SettingsActivity)) {
Intent intent = new Intent(BaseActivity.this, SettingsActivity.class);
startActivity(intent);
}
} }
drawer.closeDrawer(); drawer.closeDrawer();
@ -346,7 +368,7 @@ public abstract class BaseActivity extends AppCompatActivity {
}); });
if (sessionManager.isLoggedIn()) if (sessionManager.isLoggedIn())
drawerBuilder.addDrawerItems(homeItem, bookmarksItem, downloadsItem, loginLogoutItem, aboutItem); drawerBuilder.addDrawerItems(homeItem, bookmarksItem, downloadsItem, settingsItem, loginLogoutItem, aboutItem);
else else
drawerBuilder.addDrawerItems(homeItem, bookmarksItem, loginLogoutItem, aboutItem); drawerBuilder.addDrawerItems(homeItem, bookmarksItem, loginLogoutItem, aboutItem);
@ -369,13 +391,20 @@ public abstract class BaseActivity extends AppCompatActivity {
if (!sessionManager.isLoggedIn()) //When logged out or if user is guest if (!sessionManager.isLoggedIn()) //When logged out or if user is guest
{ {
drawer.removeItem(DOWNLOADS_ID); drawer.removeItem(DOWNLOADS_ID);
drawer.removeItem(SETTINGS_ID);
loginLogoutItem.withName(R.string.login).withIcon(loginIcon); //Swap logout with login loginLogoutItem.withName(R.string.login).withIcon(loginIcon); //Swap logout with login
profileDrawerItem.withName(sessionManager.getUsername()); profileDrawerItem.withName(sessionManager.getUsername());
setDefaultAvatar(); setDefaultAvatar();
} else { } else {
if (!drawer.getDrawerItems().contains(downloadsItem)){
drawer.addItemAtPosition(settingsItem, 2);
}
if (!drawer.getDrawerItems().contains(settingsItem)){
drawer.addItemAtPosition(settingsItem, 3);
}
loginLogoutItem.withName(R.string.logout).withIcon(logoutIcon); //Swap login with logout loginLogoutItem.withName(R.string.logout).withIcon(logoutIcon); //Swap login with logout
profileDrawerItem.withName(sessionManager.getUsername()); profileDrawerItem.withName(sessionManager.getUsername());
if(sessionManager.hasAvatar()) if (sessionManager.hasAvatar())
profileDrawerItem.withIcon(sessionManager.getAvatarLink()); profileDrawerItem.withIcon(sessionManager.getAvatarLink());
else else
setDefaultAvatar(); setDefaultAvatar();
@ -422,9 +451,9 @@ public abstract class BaseActivity extends AppCompatActivity {
mainActivity.updateTabs(); mainActivity.updateTabs();
progressDialog.dismiss(); progressDialog.dismiss();
//if (BaseActivity.this instanceof TopicActivity){ //if (BaseActivity.this instanceof TopicActivity){
Intent intent = new Intent(BaseActivity.this, MainActivity.class); Intent intent = new Intent(BaseActivity.this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent); startActivity(intent);
//} //}
} }
} }
@ -560,12 +589,12 @@ public abstract class BaseActivity extends AppCompatActivity {
else if (bookmark.matchExists(topicsBookmarked)) toggleTopicToBookmarks(bookmark); else if (bookmark.matchExists(topicsBookmarked)) toggleTopicToBookmarks(bookmark);
} }
protected boolean toggleNotification(Bookmark bookmark){ protected boolean toggleNotification(Bookmark bookmark) {
if (bookmark.matchExists(topicsBookmarked)){ if (bookmark.matchExists(topicsBookmarked)) {
topicsBookmarked.get(bookmark.findIndex(topicsBookmarked)).toggleNotificationsEnabled(); topicsBookmarked.get(bookmark.findIndex(topicsBookmarked)).toggleNotificationsEnabled();
updateTopicBookmarks(); updateTopicBookmarks();
if (topicsBookmarked.get(bookmark.findIndex(topicsBookmarked)).isNotificationsEnabled()){ if (topicsBookmarked.get(bookmark.findIndex(topicsBookmarked)).isNotificationsEnabled()) {
FirebaseMessaging.getInstance().subscribeToTopic(bookmark.getId()); FirebaseMessaging.getInstance().subscribeToTopic(bookmark.getId());
} else { } else {
FirebaseMessaging.getInstance().unsubscribeFromTopic(bookmark.getId()); FirebaseMessaging.getInstance().unsubscribeFromTopic(bookmark.getId());
@ -634,9 +663,9 @@ public abstract class BaseActivity extends AppCompatActivity {
prepareDownload(tempThmmyFile); prepareDownload(tempThmmyFile);
} }
private void prepareDownload(ThmmyFile thmmyFile){ private void prepareDownload(ThmmyFile thmmyFile) {
String fileName = thmmyFile.getFilename(); String fileName = thmmyFile.getFilename();
if(FileUtils.fileNameExists(fileName)) if (FileUtils.fileNameExists(fileName))
openDownloadPrompt(thmmyFile); openDownloadPrompt(thmmyFile);
else else
DownloadHelper.enqueueDownload(thmmyFile); DownloadHelper.enqueueDownload(thmmyFile);
@ -647,7 +676,7 @@ public abstract class BaseActivity extends AppCompatActivity {
final BottomSheetDialog dialog = new BottomSheetDialog(this); final BottomSheetDialog dialog = new BottomSheetDialog(this);
dialog.setContentView(view); dialog.setContentView(view);
TextView downloadPromptTextView = view.findViewById(R.id.downloadPromptTextView); TextView downloadPromptTextView = view.findViewById(R.id.downloadPromptTextView);
downloadPromptTextView.setText(getString(R.string.downloadPromptText,thmmyFile.getFilename())); downloadPromptTextView.setText(getString(R.string.downloadPromptText, thmmyFile.getFilename()));
Button cancelButton = view.findViewById(R.id.cancel); Button cancelButton = view.findViewById(R.id.cancel);
Button openButton = view.findViewById(R.id.open); Button openButton = view.findViewById(R.id.open);
Button downloadButton = view.findViewById(R.id.download); Button downloadButton = view.findViewById(R.id.download);
@ -661,15 +690,15 @@ public abstract class BaseActivity extends AppCompatActivity {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
dialog.dismiss(); dialog.dismiss();
try{ try {
String fileName = thmmyFile.getFilename(); String fileName = thmmyFile.getFilename();
Intent intent = new Intent(Intent.ACTION_VIEW); Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_GRANT_READ_URI_PERMISSION); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_GRANT_READ_URI_PERMISSION);
Uri fileUri = FileProvider.getUriForFile(getApplicationContext(), getPackageName() + ".provider", new File(SAVE_DIR, fileName)); Uri fileUri = FileProvider.getUriForFile(getApplicationContext(), getPackageName() + ".provider", new File(SAVE_DIR, fileName));
intent.setDataAndType(fileUri, getMimeType(fileName)); intent.setDataAndType(fileUri, getMimeType(fileName));
BaseActivity.this.startActivity(intent); BaseActivity.this.startActivity(intent);
}catch (Exception e){ } catch (Exception e) {
Timber.e(e,"Couldn't open downloaded file..."); Timber.e(e, "Couldn't open downloaded file...");
Toast.makeText(getBaseContext(), "Couldn't open file...", Toast.LENGTH_SHORT).show(); Toast.makeText(getBaseContext(), "Couldn't open file...", Toast.LENGTH_SHORT).show();
} }

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

@ -6,11 +6,14 @@ import android.app.NotificationManager;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.service.notification.StatusBarNotification; import android.service.notification.StatusBarNotification;
import android.support.annotation.RequiresApi; import android.support.annotation.RequiresApi;
import android.support.v4.app.NotificationCompat; import android.support.v4.app.NotificationCompat;
import android.support.v7.preference.PreferenceManager;
import com.google.firebase.messaging.FirebaseMessagingService; import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage; import com.google.firebase.messaging.RemoteMessage;
@ -25,6 +28,9 @@ import gr.thmmy.mthmmy.model.PostNotification;
import timber.log.Timber; import timber.log.Timber;
import static android.support.v4.app.NotificationCompat.PRIORITY_MAX; import static android.support.v4.app.NotificationCompat.PRIORITY_MAX;
import static gr.thmmy.mthmmy.activities.settings.SettingsActivity.NOTIFICATION_VIBRATION_KEY;
import static gr.thmmy.mthmmy.activities.settings.SettingsFragment.SELECTED_RINGTONE;
import static gr.thmmy.mthmmy.activities.settings.SettingsFragment.SETTINGS_SHARED_PREFS;
import static gr.thmmy.mthmmy.activities.topic.TopicActivity.BUNDLE_TOPIC_TITLE; import static gr.thmmy.mthmmy.activities.topic.TopicActivity.BUNDLE_TOPIC_TITLE;
import static gr.thmmy.mthmmy.activities.topic.TopicActivity.BUNDLE_TOPIC_URL; import static gr.thmmy.mthmmy.activities.topic.TopicActivity.BUNDLE_TOPIC_URL;
@ -40,15 +46,13 @@ public class NotificationService extends FirebaseMessagingService {
try { try {
int userId = BaseApplication.getInstance().getSessionManager().getUserId(); int userId = BaseApplication.getInstance().getSessionManager().getUserId();
//Don't notify me if the sender is me! //Don't notify me if the sender is me!
if(Integer.parseInt(json.getString("posterId"))!= userId) if (Integer.parseInt(json.getString("posterId")) != userId) {
{
int topicId = Integer.parseInt(json.getString("topicId")); int topicId = Integer.parseInt(json.getString("topicId"));
int postId = Integer.parseInt(json.getString("postId")); int postId = Integer.parseInt(json.getString("postId"));
String topicTitle = json.getString("topicTitle"); String topicTitle = json.getString("topicTitle");
String poster = json.getString("poster"); String poster = json.getString("poster");
sendNotification(new PostNotification(postId, topicId, topicTitle, poster)); sendNotification(new PostNotification(postId, topicId, topicTitle, poster));
} } else
else
Timber.v("Notification suppressed (own userID)."); Timber.v("Notification suppressed (own userID).");
} catch (JSONException e) { } catch (JSONException e) {
Timber.e(e, "JSON Exception"); Timber.e(e, "JSON Exception");
@ -64,13 +68,26 @@ public class NotificationService extends FirebaseMessagingService {
private static final String NEW_POSTS_COUNT = "newPostsCount"; private static final String NEW_POSTS_COUNT = "newPostsCount";
public static final String NEW_POST_TAG = "NEW_POST"; public static final String NEW_POST_TAG = "NEW_POST";
private static final String SUMMARY_TAG = "SUMMARY"; private static final String SUMMARY_TAG = "SUMMARY";
private static final String DELETED_MESSAGES_TAG = "DELETED_MESSAGES";
/** /**
* Create and show a new post notification. * Create and show a new post notification.
*/ */
private void sendNotification(PostNotification postNotification) { private void sendNotification(PostNotification postNotification) {
Timber.i("Creating a notification..."); Timber.i("Creating a notification...");
SharedPreferences settingsFile = getSharedPreferences(SETTINGS_SHARED_PREFS, Context.MODE_PRIVATE);
Uri notificationSoundUri = Uri.parse(settingsFile.getString(SELECTED_RINGTONE, null));
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
boolean notificationsVibrateEnabled = sharedPrefs.getBoolean(NOTIFICATION_VIBRATION_KEY, true);
int notificationDefaultValues = Notification.DEFAULT_LIGHTS;
if (notificationsVibrateEnabled) {
notificationDefaultValues |= Notification.DEFAULT_VIBRATE;
}
if (notificationSoundUri == null) {
notificationDefaultValues |= Notification.DEFAULT_SOUND;
}
String topicUrl = "https://www.thmmy.gr/smf/index.php?topic=" + postNotification.getTopicId() + "." + postNotification.getPostId(); String topicUrl = "https://www.thmmy.gr/smf/index.php?topic=" + postNotification.getTopicId() + "." + postNotification.getPostId();
Intent intent = new Intent(this, TopicActivity.class); Intent intent = new Intent(this, TopicActivity.class);
Bundle extras = new Bundle(); Bundle extras = new Bundle();
@ -85,10 +102,9 @@ public class NotificationService extends FirebaseMessagingService {
String contentText = "New post by " + postNotification.getPoster(); String contentText = "New post by " + postNotification.getPoster();
int newPostsCount = 1; int newPostsCount = 1;
if (buildVersion >= Build.VERSION_CODES.M){ if (buildVersion >= Build.VERSION_CODES.M) {
Notification existingNotification = getActiveNotification(topicId); Notification existingNotification = getActiveNotification(topicId);
if(existingNotification!=null) if (existingNotification != null) {
{
newPostsCount = existingNotification.extras.getInt(NEW_POSTS_COUNT) + 1; newPostsCount = existingNotification.extras.getInt(NEW_POSTS_COUNT) + 1;
contentText = newPostsCount + " new posts"; contentText = newPostsCount + " new posts";
} }
@ -99,29 +115,35 @@ public class NotificationService extends FirebaseMessagingService {
NotificationCompat.Builder notificationBuilder = NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(this, CHANNEL_ID) new NotificationCompat.Builder(this, CHANNEL_ID)
.setSmallIcon(R.mipmap.ic_launcher) .setSmallIcon(R.drawable.ic_notification)
.setContentTitle(postNotification.getTopicTitle()) .setContentTitle(postNotification.getTopicTitle())
.setContentText(contentText) .setContentText(contentText)
.setAutoCancel(true) .setAutoCancel(true)
.setContentIntent(pendingIntent) .setContentIntent(pendingIntent)
.setDefaults(Notification.DEFAULT_ALL) .setDefaults(notificationDefaultValues)
.setGroup(GROUP_KEY) .setGroup(GROUP_KEY)
.addExtras(notificationExtras); .addExtras(notificationExtras);
//Checks for values other than defaults and applies them
if (notificationSoundUri != null) {
notificationBuilder.setSound(notificationSoundUri);
}
if (!notificationsVibrateEnabled) {
notificationBuilder.setVibrate(new long[]{0L});
}
if (buildVersion < Build.VERSION_CODES.O) if (buildVersion < Build.VERSION_CODES.O)
notificationBuilder.setPriority(PRIORITY_MAX); notificationBuilder.setPriority(PRIORITY_MAX);
boolean createSummaryNotification = false; boolean createSummaryNotification = false;
if(buildVersion >= Build.VERSION_CODES.M) if (buildVersion >= Build.VERSION_CODES.M)
createSummaryNotification = otherNotificationsExist(topicId); createSummaryNotification = otherNotificationsExist(topicId);
NotificationCompat.Builder summaryNotificationBuilder = null; NotificationCompat.Builder summaryNotificationBuilder = null;
if(createSummaryNotification) if (createSummaryNotification) {
{
summaryNotificationBuilder = summaryNotificationBuilder =
new NotificationCompat.Builder(this, CHANNEL_ID) new NotificationCompat.Builder(this, CHANNEL_ID)
.setSmallIcon(R.mipmap.ic_launcher) .setSmallIcon(R.drawable.ic_notification)
.setGroupSummary(true) .setGroupSummary(true)
.setGroup(GROUP_KEY) .setGroup(GROUP_KEY)
.setAutoCancel(true) .setAutoCancel(true)
@ -131,8 +153,6 @@ public class NotificationService extends FirebaseMessagingService {
} }
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// Since Android Oreo notification channel is needed. // Since Android Oreo notification channel is needed.
@ -141,17 +161,16 @@ public class NotificationService extends FirebaseMessagingService {
notificationManager.notify(NEW_POST_TAG, topicId, notificationBuilder.build()); notificationManager.notify(NEW_POST_TAG, topicId, notificationBuilder.build());
if(createSummaryNotification) if (createSummaryNotification)
notificationManager.notify(SUMMARY_TAG,0, summaryNotificationBuilder.build()); notificationManager.notify(SUMMARY_TAG, 0, summaryNotificationBuilder.build());
} }
@RequiresApi(api = Build.VERSION_CODES.M) @RequiresApi(api = Build.VERSION_CODES.M)
private Notification getActiveNotification(int notificationId) { private Notification getActiveNotification(int notificationId) {
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
if(notificationManager!=null) if (notificationManager != null) {
{
StatusBarNotification[] barNotifications = notificationManager.getActiveNotifications(); StatusBarNotification[] barNotifications = notificationManager.getActiveNotifications();
for(StatusBarNotification notification: barNotifications) { for (StatusBarNotification notification : barNotifications) {
if (notification.getId() == notificationId) if (notification.getId() == notificationId)
return notification.getNotification(); return notification.getNotification();
} }
@ -161,13 +180,13 @@ public class NotificationService extends FirebaseMessagingService {
} }
@RequiresApi(api = Build.VERSION_CODES.M) @RequiresApi(api = Build.VERSION_CODES.M)
private boolean otherNotificationsExist(int notificationId){ private boolean otherNotificationsExist(int notificationId) {
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
if(notificationManager!=null) { if (notificationManager != null) {
StatusBarNotification[] barNotifications = notificationManager.getActiveNotifications(); StatusBarNotification[] barNotifications = notificationManager.getActiveNotifications();
for (StatusBarNotification notification : barNotifications) { for (StatusBarNotification notification : barNotifications) {
String tag = notification.getTag(); String tag = notification.getTag();
if (tag!=null && tag.equals(NEW_POST_TAG) && notification.getId() != notificationId) if (tag != null && tag.equals(NEW_POST_TAG) && notification.getId() != notificationId)
return true; return true;
} }
} }
@ -177,24 +196,8 @@ public class NotificationService extends FirebaseMessagingService {
@Override @Override
public void onDeletedMessages() { public void onDeletedMessages() {
super.onDeletedMessages(); super.onDeletedMessages();
NotificationCompat.Builder notificationBuilder = Timber.w("onDeletedMessages");
new NotificationCompat.Builder(this, CHANNEL_ID) }
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("Error fetching notifications!")
.setContentText("Some notifications may not have arrived successfully either due to" +
"the amount of pending messages (>100) or if the device hasn't come online for more than a month.")
.setAutoCancel(true)
.setDefaults(Notification.DEFAULT_ALL);
if (buildVersion < Build.VERSION_CODES.O)
notificationBuilder.setPriority(Notification.PRIORITY_MAX);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// Since Android Oreo notification channel is needed.
if (buildVersion >= Build.VERSION_CODES.O)
notificationManager.createNotificationChannel(new NotificationChannel(CHANNEL_ID, CHANNEL_NAME, NotificationManager.IMPORTANCE_HIGH));
notificationManager.notify(DELETED_MESSAGES_TAG, 0, notificationBuilder.build());
}
} }

BIN
app/src/main/res/drawable-hdpi/ic_notification.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 581 B

BIN
app/src/main/res/drawable-mdpi/ic_notification.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 418 B

BIN
app/src/main/res/drawable-xhdpi/ic_notification.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 800 B

BIN
app/src/main/res/drawable-xxhdpi/ic_notification.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

4
app/src/main/res/layout/activity_bookmark.xml

@ -54,6 +54,4 @@
app:layout_anchorGravity="bottom|center" app:layout_anchorGravity="bottom|center"
app:mpb_indeterminateTint="@color/accent" app:mpb_indeterminateTint="@color/accent"
app:mpb_progressStyle="horizontal"/> app:mpb_progressStyle="horizontal"/>
</android.support.design.widget.CoordinatorLayout> </android.support.design.widget.CoordinatorLayout>

33
app/src/main/res/layout/activity_settings.xml

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".activities.settings.SettingsActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/appbar_padding_top"
android:theme="@style/ToolbarTheme">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:gravity="center"
app:popupTheme="@style/ToolbarTheme" />
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="@+id/pref_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>

1
app/src/main/res/values-v21/styles.xml

@ -24,5 +24,6 @@
<item name="windowNoTitle">true</item> <item name="windowNoTitle">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item> <item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">@android:color/transparent</item> <item name="android:statusBarColor">@android:color/transparent</item>
<item name="preferenceTheme">@style/PreferenceThemeOverlay.v14.Material</item>
</style> </style>
</resources> </resources>

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

@ -6,6 +6,7 @@
<string name="login_spinner">Authenticating&#8230;</string> <string name="login_spinner">Authenticating&#8230;</string>
<string name="logout">Logout</string> <string name="logout">Logout</string>
<string name="downloads">Downloads</string> <string name="downloads">Downloads</string>
<string name="settings">Settings</string>
<string name="about">About</string> <string name="about">About</string>
<string name="home">Home</string> <string name="home">Home</string>
<string name="bookmark">Bookmarks</string> <string name="bookmark">Bookmarks</string>
@ -74,6 +75,7 @@
<string name="remove_bookmark">Remove</string> <string name="remove_bookmark">Remove</string>
<string name="empty_board_bookmarks">You have no bookmarked boards</string> <string name="empty_board_bookmarks">You have no bookmarked boards</string>
<string name="empty_topic_bookmarks">You have no bookmarked topics</string> <string name="empty_topic_bookmarks">You have no bookmarked topics</string>
<string name="toggle_notification">Toggle Notification</string>
<!--FontAwesome--> <!--FontAwesome-->
<string name="fa_icon_star">&#xf005;</string> <string name="fa_icon_star">&#xf005;</string>
@ -91,13 +93,26 @@
<string name="fa_circle">&#xf111;</string> <string name="fa_circle">&#xf111;</string>
<string name="fa_thumbtack">&#xf08d;</string> <string name="fa_thumbtack">&#xf08d;</string>
<!--Notifications-->
<string name="toggle_notification">Toggle Notification</string>
<!--Download Prompt--> <!--Download Prompt-->
<string name="downloadPromptText">File \"%1$s\" already exists. Download again?"</string> <string name="downloadPromptText">File \"%1$s\" already exists. Download again?"</string>
<string name="download_symbol">Download Symbol</string> <string name="download_symbol">Download Symbol</string>
<string name="cancel">Cancel</string> <string name="cancel">Cancel</string>
<string name="open">Open</string> <string name="open">Open</string>
<string name="download">Download</string> <string name="download">Download</string>
<!--Settings Activity-->
<string name="action_settings">Settings</string>
<string name="title_activity_settings">Settings</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_summary_notification_vibration_enable">Summary</string>
<string name="pref_title_notifications_sound">Notifications sound</string>
<string name="pref_summary_notifications_sound">Select your preferred notification sound</string>
<string name="pref_category_posting">Posting</string>
<string name="pref_title_posting_app_signature_enable">App signature</string>
<string name="pref_summary_posting_app_signature_enable">If enabled, a \"Posted from mThmmy\" message will be inserted at the end of your posts</string>
</resources> </resources>

1
app/src/main/res/values/styles.xml

@ -23,6 +23,7 @@
<style name="AppTheme.NoActionBar"> <style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item> <item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item> <item name="windowNoTitle">true</item>
<item name="preferenceTheme">@style/PreferenceThemeOverlay.v14.Material</item>
</style> </style>
<style name="ToolbarTheme" parent="ThemeOverlay.AppCompat.Light"> <style name="ToolbarTheme" parent="ThemeOverlay.AppCompat.Light">

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

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<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:summary="@string/pref_summary_notification_vibration_enable"
android:title="@string/pref_title_notification_vibration_enable" />
<Preference
android:key="pref_notifications_select_sound_key"
android:summary="@string/pref_summary_notifications_sound"
android:title="@string/pref_title_notifications_sound" />
</android.support.v7.preference.PreferenceCategory>
<android.support.v7.preference.PreferenceCategory 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.support.v7.preference.PreferenceCategory>
</android.support.v7.preference.PreferenceScreen>
Loading…
Cancel
Save