diff --git a/app/src/main/java/com/keylesspalace/tusky/AccountActivity.java b/app/src/main/java/com/keylesspalace/tusky/AccountActivity.java index 653bf601..c25ef5ec 100644 --- a/app/src/main/java/com/keylesspalace/tusky/AccountActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/AccountActivity.java @@ -107,7 +107,7 @@ public class AccountActivity extends BaseActivity { int pageMargin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, getResources().getDisplayMetrics()); viewPager.setPageMargin(pageMargin); - viewPager.setPageMarginDrawable(R.drawable.tab_page_margin); + viewPager.setPageMarginDrawable(R.drawable.tab_page_margin_dark); viewPager.setAdapter(adapter); tabLayout = (TabLayout) findViewById(R.id.tab_layout); tabLayout.setupWithViewPager(viewPager); diff --git a/app/src/main/java/com/keylesspalace/tusky/AccountFragment.java b/app/src/main/java/com/keylesspalace/tusky/AccountFragment.java index 3eb3868b..05131b8a 100644 --- a/app/src/main/java/com/keylesspalace/tusky/AccountFragment.java +++ b/app/src/main/java/com/keylesspalace/tusky/AccountFragment.java @@ -99,7 +99,7 @@ public class AccountFragment extends Fragment implements AccountActionListener, recyclerView.setLayoutManager(layoutManager); DividerItemDecoration divider = new DividerItemDecoration( context, layoutManager.getOrientation()); - Drawable drawable = ContextCompat.getDrawable(context, R.drawable.status_divider); + Drawable drawable = ContextCompat.getDrawable(context, R.drawable.status_divider_dark); divider.setDrawable(drawable); recyclerView.addItemDecoration(divider); scrollListener = new EndlessOnScrollListener(layoutManager) { diff --git a/app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java b/app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java index beac9903..d9157818 100644 --- a/app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java @@ -242,15 +242,6 @@ public class ComposeActivity extends BaseActivity { } } - private static int getThemeColor(Context context, int attribute) { - TypedValue value = new TypedValue(); - if (context.getTheme().resolveAttribute(attribute, value, true)) { - return value.data; - } else { - return android.R.color.black; - } - } - @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -270,7 +261,7 @@ public class ComposeActivity extends BaseActivity { textEditor = (EditText) findViewById(R.id.field_status); final TextView charactersLeft = (TextView) findViewById(R.id.characters_left); - final int mentionColour = getThemeColor(this, R.attr.compose_mention_color); + final int mentionColour = ThemeUtils.getColor(this, R.attr.compose_mention_color); TextWatcher textEditorWatcher = new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { diff --git a/app/src/main/java/com/keylesspalace/tusky/LoginActivity.java b/app/src/main/java/com/keylesspalace/tusky/LoginActivity.java index 582cdf9c..7da68a30 100644 --- a/app/src/main/java/com/keylesspalace/tusky/LoginActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/LoginActivity.java @@ -205,10 +205,12 @@ public class LoginActivity extends BaseActivity { editor.putString("domain", domain); editor.putString("clientId", clientId); editor.putString("clientSecret", clientSecret); - editor.commit(); + editor.apply(); } private void onLoginSuccess(String accessToken) { + preferences = getSharedPreferences( + getString(R.string.preferences_file_key), Context.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); editor.putString("accessToken", accessToken); editor.apply(); @@ -233,6 +235,8 @@ public class LoginActivity extends BaseActivity { /* During the redirect roundtrip this Activity usually dies, which wipes out the * instance variables, so they have to be recovered from where they were saved in * SharedPreferences. */ + preferences = getSharedPreferences( + getString(R.string.preferences_file_key), Context.MODE_PRIVATE); domain = preferences.getString("domain", null); clientId = preferences.getString("clientId", null); clientSecret = preferences.getString("clientSecret", null); @@ -247,6 +251,7 @@ public class LoginActivity extends BaseActivity { parameters.put("grant_type", "authorization_code"); } catch (JSONException e) { errorText.setText("Heck."); + return; //TODO: I don't even know how to handle this error state. } String endpoint = getString(R.string.endpoint_token); @@ -256,11 +261,12 @@ public class LoginActivity extends BaseActivity { new Response.Listener() { @Override public void onResponse(JSONObject response) { - String accessToken = ""; + String accessToken; try { accessToken = response.getString("access_token"); } catch(JSONException e) { errorText.setText("Heck."); + return; //TODO: I don't even know how to handle this error state. } onLoginSuccess(accessToken); diff --git a/app/src/main/java/com/keylesspalace/tusky/MainActivity.java b/app/src/main/java/com/keylesspalace/tusky/MainActivity.java index 317e3a97..f40f1ded 100644 --- a/app/src/main/java/com/keylesspalace/tusky/MainActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/MainActivity.java @@ -20,6 +20,7 @@ import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; +import android.graphics.drawable.Drawable; import android.os.SystemClock; import android.preference.PreferenceManager; import android.support.design.widget.TabLayout; @@ -72,7 +73,9 @@ public class MainActivity extends BaseActivity { ViewPager viewPager = (ViewPager) findViewById(R.id.pager); int pageMargin = getResources().getDimensionPixelSize(R.dimen.tab_page_margin); viewPager.setPageMargin(pageMargin); - viewPager.setPageMarginDrawable(R.drawable.tab_page_margin); + Drawable pageMarginDrawable = ThemeUtils.getDrawable(this, R.attr.tab_page_margin_drawable, + R.drawable.tab_page_margin_dark); + viewPager.setPageMarginDrawable(pageMarginDrawable); viewPager.setAdapter(adapter); TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout); tabLayout.setupWithViewPager(viewPager); diff --git a/app/src/main/java/com/keylesspalace/tusky/NotificationsFragment.java b/app/src/main/java/com/keylesspalace/tusky/NotificationsFragment.java index b14ff211..552f6e9b 100644 --- a/app/src/main/java/com/keylesspalace/tusky/NotificationsFragment.java +++ b/app/src/main/java/com/keylesspalace/tusky/NotificationsFragment.java @@ -77,7 +77,7 @@ public class NotificationsFragment extends SFragment implements recyclerView.setLayoutManager(layoutManager); DividerItemDecoration divider = new DividerItemDecoration( context, layoutManager.getOrientation()); - Drawable drawable = ContextCompat.getDrawable(context, R.drawable.status_divider); + Drawable drawable = ContextCompat.getDrawable(context, R.drawable.status_divider_dark); divider.setDrawable(drawable); recyclerView.addItemDecoration(divider); scrollListener = new EndlessOnScrollListener(layoutManager) { diff --git a/app/src/main/java/com/keylesspalace/tusky/PullNotificationService.java b/app/src/main/java/com/keylesspalace/tusky/PullNotificationService.java index 94862ade..63fa2a3f 100644 --- a/app/src/main/java/com/keylesspalace/tusky/PullNotificationService.java +++ b/app/src/main/java/com/keylesspalace/tusky/PullNotificationService.java @@ -154,18 +154,22 @@ public class PullNotificationService extends IntentService { } private void loadAvatar(final List mentions, String url) { - ImageRequest request = new ImageRequest(url, new Response.Listener() { - @Override - public void onResponse(Bitmap response) { - updateNotification(mentions, response); - } - }, 0, 0, null, null, new Response.ErrorListener() { - @Override - public void onErrorResponse(VolleyError error) { - updateNotification(mentions, null); - } - }); - VolleySingleton.getInstance(this).addToRequestQueue(request); + if (url != null) { + ImageRequest request = new ImageRequest(url, new Response.Listener() { + @Override + public void onResponse(Bitmap response) { + updateNotification(mentions, response); + } + }, 0, 0, null, null, new Response.ErrorListener() { + @Override + public void onErrorResponse(VolleyError error) { + updateNotification(mentions, null); + } + }); + VolleySingleton.getInstance(this).addToRequestQueue(request); + } else { + updateNotification(mentions, null); + } } private void updateNotification(List mentions, @Nullable Bitmap icon) { diff --git a/app/src/main/java/com/keylesspalace/tusky/StatusViewHolder.java b/app/src/main/java/com/keylesspalace/tusky/StatusViewHolder.java index bfccc1f7..7ded23d1 100644 --- a/app/src/main/java/com/keylesspalace/tusky/StatusViewHolder.java +++ b/app/src/main/java/com/keylesspalace/tusky/StatusViewHolder.java @@ -80,10 +80,12 @@ public class StatusViewHolder extends RecyclerView.ViewHolder { mediaPreview1 = (NetworkImageView) itemView.findViewById(R.id.status_media_preview_1); mediaPreview2 = (NetworkImageView) itemView.findViewById(R.id.status_media_preview_2); mediaPreview3 = (NetworkImageView) itemView.findViewById(R.id.status_media_preview_3); - mediaPreview0.setDefaultImageResId(R.drawable.media_preview_unloaded); - mediaPreview1.setDefaultImageResId(R.drawable.media_preview_unloaded); - mediaPreview2.setDefaultImageResId(R.drawable.media_preview_unloaded); - mediaPreview3.setDefaultImageResId(R.drawable.media_preview_unloaded); + int mediaPreviewUnloadedId = ThemeUtils.getDrawableId(itemView.getContext(), + R.attr.media_preview_unloaded_drawable, android.R.color.black); + mediaPreview0.setDefaultImageResId(mediaPreviewUnloadedId); + mediaPreview1.setDefaultImageResId(mediaPreviewUnloadedId); + mediaPreview2.setDefaultImageResId(mediaPreviewUnloadedId); + mediaPreview3.setDefaultImageResId(mediaPreviewUnloadedId); sensitiveMediaWarning = itemView.findViewById(R.id.status_sensitive_media_warning); contentWarningBar = itemView.findViewById(R.id.status_content_warning_bar); contentWarningDescription = diff --git a/app/src/main/java/com/keylesspalace/tusky/ThemeUtils.java b/app/src/main/java/com/keylesspalace/tusky/ThemeUtils.java new file mode 100644 index 00000000..8ca91612 --- /dev/null +++ b/app/src/main/java/com/keylesspalace/tusky/ThemeUtils.java @@ -0,0 +1,52 @@ +/* Copyright 2017 Andrew Dawson + * + * This file is part of Tusky. + * + * Tusky is free software: you can redistribute it and/or modify it under the terms of the GNU + * General Public License as published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * Tusky is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even + * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + * Public License for more details. + * + * You should have received a copy of the GNU General Public License along with Tusky. If not, see + * . */ + +package com.keylesspalace.tusky; + +import android.content.Context; +import android.graphics.drawable.Drawable; +import android.support.v4.content.ContextCompat; +import android.util.TypedValue; + +public class ThemeUtils { + public static Drawable getDrawable(Context context, int attribute, int fallbackDrawable) { + TypedValue value = new TypedValue(); + int resourceId; + if (context.getTheme().resolveAttribute(attribute, value, true)) { + resourceId = value.resourceId; + } else { + resourceId = fallbackDrawable; + } + return ContextCompat.getDrawable(context, resourceId); + } + + public static int getDrawableId(Context context, int attribute, int fallbackDrawableId) { + TypedValue value = new TypedValue(); + if (context.getTheme().resolveAttribute(attribute, value, true)) { + return value.resourceId; + } else { + return fallbackDrawableId; + } + } + + public static int getColor(Context context, int attribute) { + TypedValue value = new TypedValue(); + if (context.getTheme().resolveAttribute(attribute, value, true)) { + return value.data; + } else { + return android.R.color.black; + } + } +} diff --git a/app/src/main/java/com/keylesspalace/tusky/TimelineFragment.java b/app/src/main/java/com/keylesspalace/tusky/TimelineFragment.java index 8fe9ad47..f13756d3 100644 --- a/app/src/main/java/com/keylesspalace/tusky/TimelineFragment.java +++ b/app/src/main/java/com/keylesspalace/tusky/TimelineFragment.java @@ -102,7 +102,8 @@ public class TimelineFragment extends SFragment implements recyclerView.setLayoutManager(layoutManager); DividerItemDecoration divider = new DividerItemDecoration( context, layoutManager.getOrientation()); - Drawable drawable = ContextCompat.getDrawable(context, R.drawable.status_divider); + Drawable drawable = ThemeUtils.getDrawable(context, R.attr.status_divider_drawable, + R.drawable.status_divider_dark); divider.setDrawable(drawable); recyclerView.addItemDecoration(divider); scrollListener = new EndlessOnScrollListener(layoutManager) { diff --git a/app/src/main/java/com/keylesspalace/tusky/ViewThreadFragment.java b/app/src/main/java/com/keylesspalace/tusky/ViewThreadFragment.java index 4e7333e7..72b77de1 100644 --- a/app/src/main/java/com/keylesspalace/tusky/ViewThreadFragment.java +++ b/app/src/main/java/com/keylesspalace/tusky/ViewThreadFragment.java @@ -60,7 +60,7 @@ public class ViewThreadFragment extends SFragment implements StatusActionListene recyclerView.setLayoutManager(layoutManager); DividerItemDecoration divider = new DividerItemDecoration( context, layoutManager.getOrientation()); - Drawable drawable = ContextCompat.getDrawable(context, R.drawable.status_divider); + Drawable drawable = ContextCompat.getDrawable(context, R.drawable.status_divider_dark); divider.setDrawable(drawable); recyclerView.addItemDecoration(divider); adapter = new ThreadAdapter(this); diff --git a/app/src/main/res/drawable/media_preview_unloaded.xml b/app/src/main/res/drawable/media_preview_unloaded_dark.xml similarity index 76% rename from app/src/main/res/drawable/media_preview_unloaded.xml rename to app/src/main/res/drawable/media_preview_unloaded_dark.xml index 9ff8a8d1..5585d288 100644 --- a/app/src/main/res/drawable/media_preview_unloaded.xml +++ b/app/src/main/res/drawable/media_preview_unloaded_dark.xml @@ -3,7 +3,7 @@ xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> - + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/status_divider.xml b/app/src/main/res/drawable/status_divider_dark.xml similarity index 72% rename from app/src/main/res/drawable/status_divider.xml rename to app/src/main/res/drawable/status_divider_dark.xml index 99cb8fff..7c6fab90 100644 --- a/app/src/main/res/drawable/status_divider.xml +++ b/app/src/main/res/drawable/status_divider_dark.xml @@ -2,5 +2,5 @@ - + \ No newline at end of file diff --git a/app/src/main/res/drawable/status_divider_light.xml b/app/src/main/res/drawable/status_divider_light.xml new file mode 100644 index 00000000..86694405 --- /dev/null +++ b/app/src/main/res/drawable/status_divider_light.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/tab_page_margin.xml b/app/src/main/res/drawable/tab_page_margin_dark.xml similarity index 67% rename from app/src/main/res/drawable/tab_page_margin.xml rename to app/src/main/res/drawable/tab_page_margin_dark.xml index cc795044..3bd2e0c2 100644 --- a/app/src/main/res/drawable/tab_page_margin.xml +++ b/app/src/main/res/drawable/tab_page_margin_dark.xml @@ -1,5 +1,5 @@ - + \ No newline at end of file diff --git a/app/src/main/res/drawable/tab_page_margin_light.xml b/app/src/main/res/drawable/tab_page_margin_light.xml new file mode 100644 index 00000000..bc46cd5f --- /dev/null +++ b/app/src/main/res/drawable/tab_page_margin_light.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml index 80ccdde1..e48b50a9 100644 --- a/app/src/main/res/values/attrs.xml +++ b/app/src/main/res/values/attrs.xml @@ -18,10 +18,10 @@ - - - + + + diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 8971cfb0..560f19b0 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -31,10 +31,10 @@ @style/AppTheme.FavouriteButton.Dark @drawable/toggle_small @color/sensitive_media_warning_background_dark - @color/media_preview_unloaded_background_dark @color/status_text_secondary_dark - @color/status_divider_dark - @color/tab_page_margin_dark + @drawable/media_preview_unloaded_dark + @drawable/status_divider_dark + @drawable/tab_page_margin_dark @color/account_header_background_dark @color/media_button_dark @color/compose_mention_dark @@ -86,10 +86,10 @@ @style/AppTheme.FavouriteButton.Light @drawable/toggle_small_light @color/sensitive_media_warning_background_light - @color/media_preview_unloaded_background_light @color/status_text_secondary_light - @color/status_divider_light - @color/tab_page_margin_light + @drawable/media_preview_unloaded_light + @drawable/status_divider_light + @drawable/tab_page_margin_light @color/account_header_background_light @color/media_button_light @color/compose_mention_light