aboutsummaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2019-08-21 08:21:17 +0000
committerAlex Ning <chineseperson5@gmail.com>2019-08-21 08:21:17 +0000
commit9bad5024ff2fe13d9fe366ed40a2ea8662620c18 (patch)
tree6b3b25091732c2c4b7882b6ebea832405e79806f /app/src/main
parent029bbc951b3b7d128b9eb1a469942a8f03676d83 (diff)
downloadinfinity-for-reddit-9bad5024ff2fe13d9fe366ed40a2ea8662620c18.tar
infinity-for-reddit-9bad5024ff2fe13d9fe366ed40a2ea8662620c18.tar.gz
infinity-for-reddit-9bad5024ff2fe13d9fe366ed40a2ea8662620c18.tar.bz2
infinity-for-reddit-9bad5024ff2fe13d9fe366ed40a2ea8662620c18.tar.lz
infinity-for-reddit-9bad5024ff2fe13d9fe366ed40a2ea8662620c18.tar.xz
infinity-for-reddit-9bad5024ff2fe13d9fe366ed40a2ea8662620c18.tar.zst
infinity-for-reddit-9bad5024ff2fe13d9fe366ed40a2ea8662620c18.zip
Fixed getting same notifications for different accounts (for real this time). Add a settings acivity but with no use now. Minor bugs fixed. Minor UI tweaks.
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/AndroidManifest.xml7
-rw-r--r--app/src/main/java/Settings/MainPreferenceFragment.java18
-rw-r--r--app/src/main/java/Settings/NotificationPreferenceFragment.java20
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java3
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java2
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java1
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/PostImageActivity.java4
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/PostVideoActivity.java5
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/PullNotificationWorker.java83
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/SettingsActivity.java103
-rw-r--r--app/src/main/res/drawable-night/ic_error_outline_black_24dp.xml9
-rw-r--r--app/src/main/res/drawable-night/ic_outline_access_time_24px.xml9
-rw-r--r--app/src/main/res/drawable-night/ic_outline_color_lens_24px.xml21
-rw-r--r--app/src/main/res/drawable-night/ic_outline_notifications_24px.xml9
-rw-r--r--app/src/main/res/drawable/ic_outline_access_time_24px.xml9
-rw-r--r--app/src/main/res/drawable/ic_outline_color_lens_24px.xml21
-rw-r--r--app/src/main/res/drawable/ic_outline_notifications_24px.xml9
-rw-r--r--app/src/main/res/layout/fragment_post.xml1
-rw-r--r--app/src/main/res/layout/settings_activity.xml26
-rw-r--r--app/src/main/res/values/arrays.xml33
-rw-r--r--app/src/main/res/values/strings.xml13
-rw-r--r--app/src/main/res/values/styles.xml4
-rw-r--r--app/src/main/res/xml/main_preferences.xml25
-rw-r--r--app/src/main/res/xml/notification_preferences.xml20
24 files changed, 419 insertions, 36 deletions
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 674b1642..5b41bd5d 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -21,8 +21,13 @@
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true">
<activity
+ android:name=".SettingsActivity"
+ android:label="@string/search_activity_label"
+ android:parentActivityName=".MainActivity"
+ android:theme="@style/PreferenceActivityTheme" />
+ <activity
android:name=".ViewMessageActivity"
- android:label="@string/view_message_activity"
+ android:label="@string/view_message_activity_label"
android:parentActivityName=".MainActivity"
android:theme="@style/AppTheme.NoActionBar" />
<activity
diff --git a/app/src/main/java/Settings/MainPreferenceFragment.java b/app/src/main/java/Settings/MainPreferenceFragment.java
new file mode 100644
index 00000000..69b688b2
--- /dev/null
+++ b/app/src/main/java/Settings/MainPreferenceFragment.java
@@ -0,0 +1,18 @@
+package Settings;
+
+
+import android.os.Bundle;
+
+import androidx.preference.PreferenceFragmentCompat;
+
+import ml.docilealligator.infinityforreddit.R;
+
+/**
+ * A simple {@link PreferenceFragmentCompat} subclass.
+ */
+public class MainPreferenceFragment extends PreferenceFragmentCompat {
+ @Override
+ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
+ setPreferencesFromResource(R.xml.main_preferences, rootKey);
+ }
+}
diff --git a/app/src/main/java/Settings/NotificationPreferenceFragment.java b/app/src/main/java/Settings/NotificationPreferenceFragment.java
new file mode 100644
index 00000000..c64d2143
--- /dev/null
+++ b/app/src/main/java/Settings/NotificationPreferenceFragment.java
@@ -0,0 +1,20 @@
+package Settings;
+
+
+import android.os.Bundle;
+
+import androidx.fragment.app.Fragment;
+import androidx.preference.PreferenceFragmentCompat;
+
+import ml.docilealligator.infinityforreddit.R;
+
+/**
+ * A simple {@link Fragment} subclass.
+ */
+public class NotificationPreferenceFragment extends PreferenceFragmentCompat {
+
+ @Override
+ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
+ setPreferencesFromResource(R.xml.notification_preferences, rootKey);
+ }
+}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java
index 26b5ede9..b832d423 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java
@@ -31,10 +31,9 @@ class AppModule {
@Provides @Named("oauth_without_authenticator")
@Singleton
- Retrofit provideOauthWithoutAuthenticatorRetrofit(OkHttpClient okHttpClient) {
+ Retrofit provideOauthWithoutAuthenticatorRetrofit() {
return new Retrofit.Builder()
.baseUrl(RedditUtils.OAUTH_API_BASE_URI)
- .client(okHttpClient)
.addConverterFactory(ScalarsConverterFactory.create())
.build();
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java
index 7c5a3da9..303ea2fb 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java
@@ -559,6 +559,8 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe
settingsLinearLayout.setOnClickListener(view -> {
drawer.closeDrawers();
+ Intent intent = new Intent(MainActivity.this, SettingsActivity.class);
+ startActivity(intent);
});
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java
index f18e3c5a..138747d3 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java
@@ -60,7 +60,6 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
private static final String IS_IN_LAZY_MODE_STATE = "IILMS";
- @BindView(R.id.coordinator_layout_post_fragment) CoordinatorLayout mCoordinatorLayout;
@BindView(R.id.recycler_view_post_fragment) RecyclerView mPostRecyclerView;
@BindView(R.id.progress_bar_post_fragment) CircleProgressBar mProgressBar;
@BindView(R.id.fetch_post_info_linear_layout_post_fragment) LinearLayout mFetchPostInfoLinearLayout;
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostImageActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostImageActivity.java
index 7343f259..98287035 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostImageActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostImageActivity.java
@@ -496,8 +496,8 @@ public class PostImageActivity extends AppCompatActivity implements FlairBottomS
startActivity(intent);
finish();
} else {
- mMemu.getItem(R.id.action_send_post_image_activity).setEnabled(true);
- mMemu.getItem(R.id.action_send_post_image_activity).getIcon().setAlpha(255);
+ mMemu.findItem(R.id.action_send_post_image_activity).setEnabled(true);
+ mMemu.findItem(R.id.action_send_post_image_activity).getIcon().setAlpha(255);
if (submitImagePostEvent.errorMessage == null || submitImagePostEvent.errorMessage.equals("")) {
Snackbar.make(coordinatorLayout, R.string.post_failed, Snackbar.LENGTH_SHORT).show();
} else {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostVideoActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostVideoActivity.java
index f9204444..1e9e5a02 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostVideoActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostVideoActivity.java
@@ -489,6 +489,9 @@ public class PostVideoActivity extends AppCompatActivity implements FlairBottomS
public void onSubmitVideoPostEvent(SubmitVideoPostEvent submitVideoPostEvent) {
isPosting = false;
mPostingSnackbar.dismiss();
+ mMemu.findItem(R.id.action_send_post_video_activity).setEnabled(true);
+ mMemu.findItem(R.id.action_send_post_video_activity).getIcon().setAlpha(255);
+
if(submitVideoPostEvent.postSuccess) {
Intent intent = new Intent(this, ViewUserDetailActivity.class);
intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY,
@@ -498,8 +501,6 @@ public class PostVideoActivity extends AppCompatActivity implements FlairBottomS
} else if(submitVideoPostEvent.errorProcessingVideo) {
Snackbar.make(coordinatorLayout, R.string.error_processing_video, Snackbar.LENGTH_SHORT).show();
} else {
- mMemu.getItem(R.id.action_send_post_video_activity).setEnabled(true);
- mMemu.getItem(R.id.action_send_post_video_activity).getIcon().setAlpha(255);
if (submitVideoPostEvent.errorMessage == null || submitVideoPostEvent.errorMessage.equals("")) {
Snackbar.make(coordinatorLayout, R.string.post_failed, Snackbar.LENGTH_SHORT).show();
} else {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PullNotificationWorker.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PullNotificationWorker.java
index 0a90e9a4..e53f43e5 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/PullNotificationWorker.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PullNotificationWorker.java
@@ -25,6 +25,7 @@ import javax.inject.Inject;
import javax.inject.Named;
import Account.Account;
+import retrofit2.Call;
import retrofit2.Response;
import retrofit2.Retrofit;
@@ -38,6 +39,10 @@ public class PullNotificationWorker extends Worker {
Retrofit mOauthWithoutAuthenticatorRetrofit;
@Inject
+ @Named("no_oauth")
+ Retrofit mRetrofit;
+
+ @Inject
RedditDataRoomDatabase redditDataRoomDatabase;
public PullNotificationWorker(@NonNull Context context, @NonNull WorkerParameters workerParams) {
@@ -56,9 +61,10 @@ public class PullNotificationWorker extends Worker {
List<Account> accounts = redditDataRoomDatabase.accountDao().getAllAccounts();
for(int accountIndex = 0; accountIndex < accounts.size(); accountIndex++) {
Account account = accounts.get(accountIndex);
+
String accountName = account.getUsername();
- Response<String> response = fetchMessages(account);
+ Response<String> response = fetchMessages(account, 1);
if(response != null && response.isSuccessful()) {
Log.i("workmanager", "has response");
@@ -162,56 +168,81 @@ public class PullNotificationWorker extends Worker {
Log.i("workmanager", "message size " + messages.size());
} else {
- Log.i("workmanager", "retry1");
- return Result.retry();
+ Log.i("workmanager", "no message");
+ return Result.success();
}
} else {
if(response != null) {
- Log.i("workmanager", "retry2 " + response.code());
+ Log.i("workmanager", "retry1 " + response.code());
}
return Result.retry();
}
}
- } catch (IOException | JSONException e) {
+ } catch (IOException e) {
e.printStackTrace();
- Log.i("workmanager", "retry3");
+ Log.i("workmanager", "retry2");
return Result.retry();
+ } catch (JSONException e) {
+ e.printStackTrace();
+ Log.i("workmanager", "json failure");
+ return Result.failure();
}
Log.i("workmanager", "success");
return Result.success();
}
- private Response<String> fetchMessages(Account account) throws IOException, JSONException {
- Response<String> response = mOauthWithoutAuthenticatorRetrofit.create(RedditAPI.class)
+ private Response<String> fetchMessages(Account account, int retryCount) throws IOException, JSONException {
+ if(retryCount < 0) {
+ return null;
+ }
+
+ Call<String> call = mOauthWithoutAuthenticatorRetrofit.create(RedditAPI.class)
.getMessages(RedditUtils.getOAuthHeader(account.getAccessToken()),
- FetchMessages.WHERE_UNREAD, null).execute();
+ FetchMessages.WHERE_INBOX, null);
+ Response<String> response = call.execute();
if(response.isSuccessful()) {
return response;
} else {
if(response.code() == 401) {
- String refreshToken = account.getRefreshToken();
-
- Map<String, String> params = new HashMap<>();
- params.put(RedditUtils.GRANT_TYPE_KEY, RedditUtils.GRANT_TYPE_REFRESH_TOKEN);
- params.put(RedditUtils.REFRESH_TOKEN_KEY, refreshToken);
-
- Response accessTokenResponse = mOauthWithoutAuthenticatorRetrofit.create(RedditAPI.class)
- .getAccessToken(RedditUtils.getHttpBasicAuthHeader(), params).execute();
- if(accessTokenResponse.isSuccessful() && accessTokenResponse.body() != null) {
- JSONObject jsonObject = new JSONObject((String) accessTokenResponse.body());
- String newAccessToken = jsonObject.getString(RedditUtils.ACCESS_TOKEN_KEY);
- account.setAccessToken(newAccessToken);
- redditDataRoomDatabase.accountDao().changeAccessToken(account.getUsername(), newAccessToken);
-
- return fetchMessages(account);
- } else {
- return null;
+ String accessToken = refreshAccessToken(account);
+ if(!accessToken.equals("")) {
+ return fetchMessages(account, retryCount - 1);
}
+
+ return null;
} else {
return null;
}
}
}
+
+ private String refreshAccessToken(Account account) {
+ String refreshToken = account.getRefreshToken();
+
+ RedditAPI api = mRetrofit.create(RedditAPI.class);
+
+ Map<String, String> params = new HashMap<>();
+ params.put(RedditUtils.GRANT_TYPE_KEY, RedditUtils.GRANT_TYPE_REFRESH_TOKEN);
+ params.put(RedditUtils.REFRESH_TOKEN_KEY, refreshToken);
+
+ Call<String> accessTokenCall = api.getAccessToken(RedditUtils.getHttpBasicAuthHeader(), params);
+ try {
+ Response response = accessTokenCall.execute();
+ if(response.isSuccessful() && response.body() != null) {
+ JSONObject jsonObject = new JSONObject(response.body().toString());
+ String newAccessToken = jsonObject.getString(RedditUtils.ACCESS_TOKEN_KEY);
+ redditDataRoomDatabase.accountDao().changeAccessToken(account.getUsername(), newAccessToken);
+
+ Log.i("access token", newAccessToken);
+ return newAccessToken;
+ }
+ return "";
+ } catch (IOException | JSONException e) {
+ e.printStackTrace();
+ }
+
+ return "";
+ }
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SettingsActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SettingsActivity.java
new file mode 100644
index 00000000..1ae29994
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SettingsActivity.java
@@ -0,0 +1,103 @@
+package ml.docilealligator.infinityforreddit;
+
+import android.content.res.Configuration;
+import android.os.Build;
+import android.os.Bundle;
+import android.view.MenuItem;
+import android.view.View;
+import android.view.Window;
+
+import androidx.annotation.NonNull;
+import androidx.appcompat.app.AppCompatActivity;
+import androidx.appcompat.widget.Toolbar;
+import androidx.core.content.ContextCompat;
+import androidx.fragment.app.Fragment;
+import androidx.preference.Preference;
+import androidx.preference.PreferenceFragmentCompat;
+
+import Settings.MainPreferenceFragment;
+import butterknife.BindView;
+import butterknife.ButterKnife;
+
+public class SettingsActivity extends AppCompatActivity implements
+ PreferenceFragmentCompat.OnPreferenceStartFragmentCallback {
+
+ private static final String TITLE_STATE = "TS";
+
+ @BindView(R.id.toolbar_settings_activity) Toolbar toolbar;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.settings_activity);
+
+ ButterKnife.bind(this);
+
+ if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ Window window = getWindow();
+ if((getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) != Configuration.UI_MODE_NIGHT_YES) {
+ window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR);
+ }
+ window.setNavigationBarColor(ContextCompat.getColor(this, R.color.navBarColor));
+ }
+
+ setSupportActionBar(toolbar);
+
+ if (savedInstanceState == null) {
+ getSupportFragmentManager()
+ .beginTransaction()
+ .replace(R.id.frame_layout_settings_activity, new MainPreferenceFragment())
+ .commit();
+ } else {
+ setTitle(savedInstanceState.getCharSequence(TITLE_STATE));
+ }
+ getSupportFragmentManager().addOnBackStackChangedListener(() -> {
+ if (getSupportFragmentManager().getBackStackEntryCount() == 0) {
+ setTitle(R.string.settings_activity_label);
+ }
+ });
+
+
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(@NonNull MenuItem item) {
+ if(item.getItemId() == android.R.id.home) {
+ onBackPressed();
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public void onSaveInstanceState(@NonNull Bundle outState) {
+ super.onSaveInstanceState(outState);
+ outState.putCharSequence(TITLE_STATE, getTitle());
+ }
+
+ @Override
+ public boolean onSupportNavigateUp() {
+ if (getSupportFragmentManager().popBackStackImmediate()) {
+ return true;
+ }
+ return super.onSupportNavigateUp();
+ }
+
+ @Override
+ public boolean onPreferenceStartFragment(PreferenceFragmentCompat caller, Preference pref) {
+ // Instantiate the new Fragment
+ final Bundle args = pref.getExtras();
+ final Fragment fragment = getSupportFragmentManager().getFragmentFactory().instantiate(
+ getClassLoader(),
+ pref.getFragment());
+ fragment.setArguments(args);
+ fragment.setTargetFragment(caller, 0);
+
+ getSupportFragmentManager().beginTransaction()
+ .replace(R.id.frame_layout_settings_activity, fragment)
+ .addToBackStack(null)
+ .commit();
+ setTitle(pref.getTitle());
+ return true;
+ }
+}
diff --git a/app/src/main/res/drawable-night/ic_error_outline_black_24dp.xml b/app/src/main/res/drawable-night/ic_error_outline_black_24dp.xml
new file mode 100644
index 00000000..e7d3eb31
--- /dev/null
+++ b/app/src/main/res/drawable-night/ic_error_outline_black_24dp.xml
@@ -0,0 +1,9 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp"
+ android:height="24dp"
+ android:viewportWidth="24.0"
+ android:viewportHeight="24.0">
+ <path
+ android:fillColor="#FFFFFFFF"
+ android:pathData="M11,15h2v2h-2zM11,7h2v6h-2zM11.99,2C6.47,2 2,6.48 2,12s4.47,10 9.99,10C17.52,22 22,17.52 22,12S17.52,2 11.99,2zM12,20c-4.42,0 -8,-3.58 -8,-8s3.58,-8 8,-8 8,3.58 8,8 -3.58,8 -8,8z"/>
+</vector>
diff --git a/app/src/main/res/drawable-night/ic_outline_access_time_24px.xml b/app/src/main/res/drawable-night/ic_outline_access_time_24px.xml
new file mode 100644
index 00000000..a846b915
--- /dev/null
+++ b/app/src/main/res/drawable-night/ic_outline_access_time_24px.xml
@@ -0,0 +1,9 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp"
+ android:height="24dp"
+ android:viewportWidth="24"
+ android:viewportHeight="24">
+ <path
+ android:fillColor="#FFFFFFFF"
+ android:pathData="M11.99,2C6.47,2 2,6.48 2,12s4.47,10 9.99,10C17.52,22 22,17.52 22,12S17.52,2 11.99,2zM12,20c-4.42,0 -8,-3.58 -8,-8s3.58,-8 8,-8 8,3.58 8,8 -3.58,8 -8,8zM12.5,7L11,7v6l5.25,3.15 0.75,-1.23 -4.5,-2.67z"/>
+</vector>
diff --git a/app/src/main/res/drawable-night/ic_outline_color_lens_24px.xml b/app/src/main/res/drawable-night/ic_outline_color_lens_24px.xml
new file mode 100644
index 00000000..d1bc2624
--- /dev/null
+++ b/app/src/main/res/drawable-night/ic_outline_color_lens_24px.xml
@@ -0,0 +1,21 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp"
+ android:height="24dp"
+ android:viewportWidth="24"
+ android:viewportHeight="24">
+ <path
+ android:fillColor="#FF000000"
+ android:pathData="M12,22C6.49,22 2,17.51 2,12S6.49,2 12,2s10,4.04 10,9c0,3.31 -2.69,6 -6,6h-1.77c-0.28,0 -0.5,0.22 -0.5,0.5 0,0.12 0.05,0.23 0.13,0.33 0.41,0.47 0.64,1.06 0.64,1.67 0,1.38 -1.12,2.5 -2.5,2.5zM12,4c-4.41,0 -8,3.59 -8,8s3.59,8 8,8c0.28,0 0.5,-0.22 0.5,-0.5 0,-0.16 -0.08,-0.28 -0.14,-0.35 -0.41,-0.46 -0.63,-1.05 -0.63,-1.65 0,-1.38 1.12,-2.5 2.5,-2.5L16,15c2.21,0 4,-1.79 4,-4 0,-3.86 -3.59,-7 -8,-7z"/>
+ <path
+ android:fillColor="#FF000000"
+ android:pathData="M6.5,11.5m-1.5,0a1.5,1.5 0,1 1,3 0a1.5,1.5 0,1 1,-3 0"/>
+ <path
+ android:fillColor="#FF000000"
+ android:pathData="M9.5,7.5m-1.5,0a1.5,1.5 0,1 1,3 0a1.5,1.5 0,1 1,-3 0"/>
+ <path
+ android:fillColor="#FF000000"
+ android:pathData="M14.5,7.5m-1.5,0a1.5,1.5 0,1 1,3 0a1.5,1.5 0,1 1,-3 0"/>
+ <path
+ android:fillColor="#FF000000"
+ android:pathData="M17.5,11.5m-1.5,0a1.5,1.5 0,1 1,3 0a1.5,1.5 0,1 1,-3 0"/>
+</vector>
diff --git a/app/src/main/res/drawable-night/ic_outline_notifications_24px.xml b/app/src/main/res/drawable-night/ic_outline_notifications_24px.xml
new file mode 100644
index 00000000..43d52df4
--- /dev/null
+++ b/app/src/main/res/drawable-night/ic_outline_notifications_24px.xml
@@ -0,0 +1,9 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp"
+ android:height="24dp"
+ android:viewportWidth="24"
+ android:viewportHeight="24">
+ <path
+ android:fillColor="#FFFFFFFF"
+ android:pathData="M12,22c1.1,0 2,-0.9 2,-2h-4c0,1.1 0.9,2 2,2zM18,16v-5c0,-3.07 -1.63,-5.64 -4.5,-6.32L13.5,4c0,-0.83 -0.67,-1.5 -1.5,-1.5s-1.5,0.67 -1.5,1.5v0.68C7.64,5.36 6,7.92 6,11v5l-2,2v1h16v-1l-2,-2zM16,17L8,17v-6c0,-2.48 1.51,-4.5 4,-4.5s4,2.02 4,4.5v6z"/>
+</vector>
diff --git a/app/src/main/res/drawable/ic_outline_access_time_24px.xml b/app/src/main/res/drawable/ic_outline_access_time_24px.xml
new file mode 100644
index 00000000..dcb0d6ec
--- /dev/null
+++ b/app/src/main/res/drawable/ic_outline_access_time_24px.xml
@@ -0,0 +1,9 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp"
+ android:height="24dp"
+ android:viewportWidth="24"
+ android:viewportHeight="24">
+ <path
+ android:fillColor="#FF000000"
+ android:pathData="M11.99,2C6.47,2 2,6.48 2,12s4.47,10 9.99,10C17.52,22 22,17.52 22,12S17.52,2 11.99,2zM12,20c-4.42,0 -8,-3.58 -8,-8s3.58,-8 8,-8 8,3.58 8,8 -3.58,8 -8,8zM12.5,7L11,7v6l5.25,3.15 0.75,-1.23 -4.5,-2.67z"/>
+</vector>
diff --git a/app/src/main/res/drawable/ic_outline_color_lens_24px.xml b/app/src/main/res/drawable/ic_outline_color_lens_24px.xml
new file mode 100644
index 00000000..d1bc2624
--- /dev/null
+++ b/app/src/main/res/drawable/ic_outline_color_lens_24px.xml
@@ -0,0 +1,21 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp"
+ android:height="24dp"
+ android:viewportWidth="24"
+ android:viewportHeight="24">
+ <path
+ android:fillColor="#FF000000"
+ android:pathData="M12,22C6.49,22 2,17.51 2,12S6.49,2 12,2s10,4.04 10,9c0,3.31 -2.69,6 -6,6h-1.77c-0.28,0 -0.5,0.22 -0.5,0.5 0,0.12 0.05,0.23 0.13,0.33 0.41,0.47 0.64,1.06 0.64,1.67 0,1.38 -1.12,2.5 -2.5,2.5zM12,4c-4.41,0 -8,3.59 -8,8s3.59,8 8,8c0.28,0 0.5,-0.22 0.5,-0.5 0,-0.16 -0.08,-0.28 -0.14,-0.35 -0.41,-0.46 -0.63,-1.05 -0.63,-1.65 0,-1.38 1.12,-2.5 2.5,-2.5L16,15c2.21,0 4,-1.79 4,-4 0,-3.86 -3.59,-7 -8,-7z"/>
+ <path
+ android:fillColor="#FF000000"
+ android:pathData="M6.5,11.5m-1.5,0a1.5,1.5 0,1 1,3 0a1.5,1.5 0,1 1,-3 0"/>
+ <path
+ android:fillColor="#FF000000"
+ android:pathData="M9.5,7.5m-1.5,0a1.5,1.5 0,1 1,3 0a1.5,1.5 0,1 1,-3 0"/>
+ <path
+ android:fillColor="#FF000000"
+ android:pathData="M14.5,7.5m-1.5,0a1.5,1.5 0,1 1,3 0a1.5,1.5 0,1 1,-3 0"/>
+ <path
+ android:fillColor="#FF000000"
+ android:pathData="M17.5,11.5m-1.5,0a1.5,1.5 0,1 1,3 0a1.5,1.5 0,1 1,-3 0"/>
+</vector>
diff --git a/app/src/main/res/drawable/ic_outline_notifications_24px.xml b/app/src/main/res/drawable/ic_outline_notifications_24px.xml
new file mode 100644
index 00000000..0c2c90a7
--- /dev/null
+++ b/app/src/main/res/drawable/ic_outline_notifications_24px.xml
@@ -0,0 +1,9 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp"
+ android:height="24dp"
+ android:viewportWidth="24"
+ android:viewportHeight="24">
+ <path
+ android:fillColor="#FF000000"
+ android:pathData="M12,22c1.1,0 2,-0.9 2,-2h-4c0,1.1 0.9,2 2,2zM18,16v-5c0,-3.07 -1.63,-5.64 -4.5,-6.32L13.5,4c0,-0.83 -0.67,-1.5 -1.5,-1.5s-1.5,0.67 -1.5,1.5v0.68C7.64,5.36 6,7.92 6,11v5l-2,2v1h16v-1l-2,-2zM16,17L8,17v-6c0,-2.48 1.51,-4.5 4,-4.5s4,2.02 4,4.5v6z"/>
+</vector>
diff --git a/app/src/main/res/layout/fragment_post.xml b/app/src/main/res/layout/fragment_post.xml
index dcacaf49..9083b01d 100644
--- a/app/src/main/res/layout/fragment_post.xml
+++ b/app/src/main/res/layout/fragment_post.xml
@@ -3,7 +3,6 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
- android:id="@+id/coordinator_layout_post_fragment"
tools:application="ml.docilealligator.infinityforreddit.PostFragment">
<com.lsjwzh.widget.materialloadingprogressbar.CircleProgressBar
diff --git a/app/src/main/res/layout/settings_activity.xml b/app/src/main/res/layout/settings_activity.xml
new file mode 100644
index 00000000..0b9ed248
--- /dev/null
+++ b/app/src/main/res/layout/settings_activity.xml
@@ -0,0 +1,26 @@
+<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ xmlns:app="http://schemas.android.com/apk/res-auto">
+
+ <com.google.android.material.appbar.AppBarLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:theme="@style/AppTheme.AppBarOverlay">
+
+ <androidx.appcompat.widget.Toolbar
+ android:id="@+id/toolbar_settings_activity"
+ android:layout_width="match_parent"
+ android:layout_height="?attr/actionBarSize"
+ app:navigationIcon="?attr/homeAsUpIndicator"
+ app:popupTheme="@style/AppTheme.PopupOverlay" />
+
+ </com.google.android.material.appbar.AppBarLayout>
+
+ <FrameLayout
+ android:id="@+id/frame_layout_settings_activity"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ app:layout_behavior="@string/appbar_scrolling_view_behavior" />
+
+</androidx.coordinatorlayout.widget.CoordinatorLayout> \ No newline at end of file
diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml
new file mode 100644
index 00000000..99955ed6
--- /dev/null
+++ b/app/src/main/res/values/arrays.xml
@@ -0,0 +1,33 @@
+<resources>
+ <string-array name="settings_notification_interval">
+ <item>1 hour</item>
+ <item>2 hours</item>
+ <item>3 hours</item>
+ <item>4 hours</item>
+ <item>6 hours</item>
+ <item>12 hours</item>
+ <item>1 day</item>
+ </string-array>
+
+ <string-array name="settings_notification_interval_values">
+ <item>1</item>
+ <item>2</item>
+ <item>3</item>
+ <item>4</item>
+ <item>6</item>
+ <item>12</item>
+ <item>24</item>
+ </string-array>
+
+ <string-array name="settings_theme">
+ <item>Light Theme</item>
+ <item>Dark Theme</item>
+ <item>Device Default</item>
+ </string-array>
+
+ <string-array name="settings_theme_values">
+ <item>0</item>
+ <item>1</item>
+ <item>2</item>
+ </string-array>
+</resources> \ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 5a245f76..dba73658 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -13,7 +13,8 @@
<string name="search_subreddits_activity_label">Subreddits</string>
<string name="edit_post_activity_label">Edit Post</string>
<string name="edit_comment_activity_label">Edit Comment</string>
- <string name="view_message_activity">Inbox</string>
+ <string name="view_message_activity_label">Inbox</string>
+ <string name="settings_activity_label">Settings</string>
<string name="navigation_drawer_open">Open navigation drawer</string>
<string name="navigation_drawer_close">Close navigation drawer</string>
@@ -239,4 +240,14 @@
<string name="label_post">Post</string>
<string name="account_switched">Account Switched. So all other pages are gone.</string>
+
+ <string name="settings_account_master_title">Account</string>
+ <string name="settings_notification_master_title">Notification</string>
+ <string name="settings_notification_enable_notification_title">Enable Notifications</string>
+ <string name="settings_notification_interval_title">Check Notifications Interval</string>
+ <string name="settings_theme_title">Theme</string>
+ <string name="settings_theme_light__theme_summary">Light Theme</string>
+ <string name="settings_theme_dark_theme_summary">Dark Theme</string>
+ <string name="settings_theme_system_default_summary">Device default</string>
+ <string name="settings_enable_nsfw_title">Enable NSFW</string>
</resources>
diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml
index 0b20ce0e..2b97cc0d 100644
--- a/app/src/main/res/values/styles.xml
+++ b/app/src/main/res/values/styles.xml
@@ -60,4 +60,8 @@
<item name="android:textColor">@color/primaryTextColor</item>
</style>
+ <style name="PreferenceActivityTheme" parent="AppTheme.NoActionBar">
+ <item name="android:textColorPrimary">@color/primaryTextColor</item>
+ </style>
+
</resources>
diff --git a/app/src/main/res/xml/main_preferences.xml b/app/src/main/res/xml/main_preferences.xml
new file mode 100644
index 00000000..5d624d7f
--- /dev/null
+++ b/app/src/main/res/xml/main_preferences.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:app="http://schemas.android.com/apk/res-auto">
+
+ <Preference
+ app:key="notification_master"
+ app:icon="@drawable/ic_outline_notifications_24px"
+ app:title="@string/settings_notification_master_title"
+ app:fragment="Settings.NotificationPreferenceFragment" />
+
+ <ListPreference
+ app:defaultValue="0"
+ app:entries="@array/settings_theme"
+ app:entryValues="@array/settings_theme_values"
+ app:key="theme"
+ app:icon="@drawable/ic_outline_color_lens_24px"
+ app:title="@string/settings_theme_title"
+ app:useSimpleSummaryProvider="true" />
+
+ <SwitchPreference
+ app:defaultValue="true"
+ app:key="nsfw"
+ app:title="@string/settings_enable_nsfw_title"/>
+
+</androidx.preference.PreferenceScreen> \ No newline at end of file
diff --git a/app/src/main/res/xml/notification_preferences.xml b/app/src/main/res/xml/notification_preferences.xml
new file mode 100644
index 00000000..1bb81106
--- /dev/null
+++ b/app/src/main/res/xml/notification_preferences.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:app="http://schemas.android.com/apk/res-auto">
+
+ <SwitchPreference
+ app:defaultValue="true"
+ app:key="enable_notification"
+ app:icon="@drawable/ic_outline_notifications_24px"
+ app:title="@string/settings_notification_enable_notification_title"/>
+
+ <ListPreference
+ app:defaultValue="2"
+ app:entries="@array/settings_notification_interval"
+ app:entryValues="@array/settings_notification_interval_values"
+ app:key="notificaiton_interval"
+ app:icon="@drawable/ic_outline_access_time_24px"
+ app:title="@string/settings_notification_interval_title"
+ app:useSimpleSummaryProvider="true" />
+
+</androidx.preference.PreferenceScreen> \ No newline at end of file