From 7d8c497c77683a249f9fe9c80d7e9b80d9ff39a9 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Wed, 5 Jun 2019 11:25:05 +0800 Subject: Fixed UI problems introduced by dark theme. --- .../infinityforreddit/AppComponent.java | 18 +++++++ .../infinityforreddit/AppModule.java | 61 ++++++++++++++++++++++ .../CommentMultiLevelRecyclerViewAdapter.java | 4 +- .../infinityforreddit/Infinity.java | 10 ++-- .../infinityforreddit/LoginActivity.java | 2 +- .../infinityforreddit/MainActivity.java | 2 +- .../infinityforreddit/NetworkComponent.java | 18 ------- .../infinityforreddit/NetworkModule.java | 61 ---------------------- .../infinityforreddit/PostFragment.java | 10 +--- .../infinityforreddit/PostRecyclerViewAdapter.java | 2 +- .../SubredditListingFragment.java | 2 +- .../infinityforreddit/UserListingFragment.java | 2 +- .../infinityforreddit/ViewPostDetailActivity.java | 6 +-- .../ViewSubredditDetailActivity.java | 2 +- .../infinityforreddit/ViewUserDetailActivity.java | 2 +- 15 files changed, 97 insertions(+), 105 deletions(-) create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/NetworkComponent.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/NetworkModule.java (limited to 'app/src/main/java/ml/docilealligator/infinityforreddit') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java new file mode 100644 index 00000000..99a5ff3f --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java @@ -0,0 +1,18 @@ +package ml.docilealligator.infinityforreddit; + +import javax.inject.Singleton; + +import dagger.Component; + +@Singleton +@Component(modules = AppModule.class) +interface AppComponent { + void inject(MainActivity mainActivity); + void inject(LoginActivity loginActivity); + void inject(PostFragment postFragment); + void inject(SubredditListingFragment subredditListingFragment); + void inject(UserListingFragment userListingFragment); + void inject(ViewPostDetailActivity viewPostDetailActivity); + void inject(ViewSubredditDetailActivity viewSubredditDetailActivity); + void inject(ViewUserDetailActivity viewUserDetailActivity); +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java new file mode 100644 index 00000000..baa2a396 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java @@ -0,0 +1,61 @@ +package ml.docilealligator.infinityforreddit; + +import android.app.Application; +import android.content.Context; +import android.content.SharedPreferences; + +import javax.inject.Named; +import javax.inject.Singleton; + +import dagger.Module; +import dagger.Provides; +import okhttp3.OkHttpClient; +import retrofit2.Retrofit; +import retrofit2.converter.scalars.ScalarsConverterFactory; + +@Module +class AppModule { + Application mApplication; + + public AppModule(Application application) { + mApplication = application; + } + + @Provides @Named("oauth") + @Singleton + Retrofit provideOauthRetrofit(OkHttpClient okHttpClient) { + return new Retrofit.Builder() + .baseUrl(RedditUtils.OAUTH_API_BASE_URI) + .client(okHttpClient) + .addConverterFactory(ScalarsConverterFactory.create()) + .build(); + } + + @Provides @Named("no_oauth") + @Singleton + Retrofit provideRetrofit() { + return new Retrofit.Builder() + .baseUrl(RedditUtils.API_BASE_URI) + .addConverterFactory(ScalarsConverterFactory.create()) + .build(); + } + + @Provides + @Singleton + OkHttpClient provideOkHttpClient(@Named("no_oauth") Retrofit retrofit, @Named("auth_info") SharedPreferences sharedPreferences) { + OkHttpClient.Builder okHttpClientBuilder = new OkHttpClient.Builder(); + okHttpClientBuilder.authenticator(new AccessTokenAuthenticator(retrofit, sharedPreferences)); + return okHttpClientBuilder.build(); + } + + @Provides @Named("auth_info") + @Singleton + SharedPreferences provideAuthInfoSharedPreferences() { + return mApplication.getSharedPreferences(SharedPreferencesUtils.AUTH_CODE_FILE_KEY, Context.MODE_PRIVATE); + } + + @Provides @Named("user_info") + SharedPreferences provideUserInfoSharedPreferences() { + return mApplication.getSharedPreferences(SharedPreferencesUtils.USER_INFO_FILE_KEY, Context.MODE_PRIVATE); + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentMultiLevelRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentMultiLevelRecyclerViewAdapter.java index e9f29f3c..6191b334 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentMultiLevelRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentMultiLevelRecyclerViewAdapter.java @@ -79,11 +79,11 @@ class CommentMultiLevelRecyclerViewAdapter extends MultiLevelAdapter { ((CommentViewHolder) holder).commentTimeTextView.setText(commentItem.getCommentTime()); SpannableConfiguration spannableConfiguration = SpannableConfiguration.builder(mContext).linkResolver((view, link) -> { - if (link.startsWith("/u/")) { + if (link.startsWith("/u/") || link.startsWith("u/")) { Intent intent = new Intent(mContext, ViewUserDetailActivity.class); intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, link.substring(3)); mContext.startActivity(intent); - } else if (link.startsWith("/r/")) { + } else if (link.startsWith("/r/") || link.startsWith("r/")) { Intent intent = new Intent(mContext, ViewSubredditDetailActivity.class); intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, link.substring(3)); mContext.startActivity(intent); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Infinity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Infinity.java index 1309bfdb..8137355b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Infinity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Infinity.java @@ -3,18 +3,18 @@ package ml.docilealligator.infinityforreddit; import android.app.Application; public class Infinity extends Application { - private NetworkComponent mNetworkComponent; + private AppComponent mAppComponent; @Override public void onCreate() { super.onCreate(); - mNetworkComponent = DaggerNetworkComponent.builder() - .networkModule(new NetworkModule(this)) + mAppComponent = DaggerAppComponent.builder() + .appModule(new AppModule(this)) .build(); } - public NetworkComponent getmNetworkComponent() { - return mNetworkComponent; + public AppComponent getmAppComponent() { + return mAppComponent; } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/LoginActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/LoginActivity.java index 063148f1..53b0e143 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/LoginActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/LoginActivity.java @@ -41,7 +41,7 @@ public class LoginActivity extends AppCompatActivity { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login); - ((Infinity) getApplication()).getmNetworkComponent().inject(this); + ((Infinity) getApplication()).getmAppComponent().inject(this); getSupportActionBar().setDisplayHomeAsUpEnabled(true); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java index 1989a47d..012c1503 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java @@ -98,7 +98,7 @@ public class MainActivity extends AppCompatActivity { setContentView(R.layout.activity_main); ButterKnife.bind(this); - ((Infinity) getApplication()).getmNetworkComponent().inject(this); + ((Infinity) getApplication()).getmAppComponent().inject(this); Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/NetworkComponent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/NetworkComponent.java deleted file mode 100644 index 4615898b..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/NetworkComponent.java +++ /dev/null @@ -1,18 +0,0 @@ -package ml.docilealligator.infinityforreddit; - -import javax.inject.Singleton; - -import dagger.Component; - -@Singleton -@Component(modules = NetworkModule.class) -interface NetworkComponent { - void inject(MainActivity mainActivity); - void inject(LoginActivity loginActivity); - void inject(PostFragment postFragment); - void inject(SubredditListingFragment subredditListingFragment); - void inject(UserListingFragment userListingFragment); - void inject(ViewPostDetailActivity viewPostDetailActivity); - void inject(ViewSubredditDetailActivity viewSubredditDetailActivity); - void inject(ViewUserDetailActivity viewUserDetailActivity); -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/NetworkModule.java b/app/src/main/java/ml/docilealligator/infinityforreddit/NetworkModule.java deleted file mode 100644 index d97929ac..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/NetworkModule.java +++ /dev/null @@ -1,61 +0,0 @@ -package ml.docilealligator.infinityforreddit; - -import android.app.Application; -import android.content.Context; -import android.content.SharedPreferences; - -import javax.inject.Named; -import javax.inject.Singleton; - -import dagger.Module; -import dagger.Provides; -import okhttp3.OkHttpClient; -import retrofit2.Retrofit; -import retrofit2.converter.scalars.ScalarsConverterFactory; - -@Module -class NetworkModule { - Application mApplication; - - public NetworkModule(Application application) { - mApplication = application; - } - - @Provides @Named("oauth") - @Singleton - Retrofit provideOauthRetrofit(OkHttpClient okHttpClient) { - return new Retrofit.Builder() - .baseUrl(RedditUtils.OAUTH_API_BASE_URI) - .client(okHttpClient) - .addConverterFactory(ScalarsConverterFactory.create()) - .build(); - } - - @Provides @Named("no_oauth") - @Singleton - Retrofit provideRetrofit() { - return new Retrofit.Builder() - .baseUrl(RedditUtils.API_BASE_URI) - .addConverterFactory(ScalarsConverterFactory.create()) - .build(); - } - - @Provides - @Singleton - OkHttpClient provideOkHttpClient(@Named("no_oauth") Retrofit retrofit, @Named("auth_info") SharedPreferences sharedPreferences) { - OkHttpClient.Builder okHttpClientBuilder = new OkHttpClient.Builder(); - okHttpClientBuilder.authenticator(new AccessTokenAuthenticator(retrofit, sharedPreferences)); - return okHttpClientBuilder.build(); - } - - @Provides @Named("auth_info") - @Singleton - SharedPreferences provideAuthInfoSharedPreferences() { - return mApplication.getSharedPreferences(SharedPreferencesUtils.AUTH_CODE_FILE_KEY, Context.MODE_PRIVATE); - } - - @Provides @Named("user_info") - SharedPreferences provideUserInfoSharedPreferences() { - return mApplication.getSharedPreferences(SharedPreferencesUtils.USER_INFO_FILE_KEY, Context.MODE_PRIVATE); - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java index de03f164..4d9cd3c7 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java @@ -83,7 +83,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { // Inflate the layout for this fragment View rootView = inflater.inflate(R.layout.fragment_post, container, false); - ((Infinity) getActivity().getApplication()).getmNetworkComponent().inject(this); + ((Infinity) getActivity().getApplication()).getmAppComponent().inject(this); ButterKnife.bind(this, rootView); @@ -91,14 +91,6 @@ public class PostFragment extends Fragment implements FragmentCommunicator { mLinearLayoutManager = new LinearLayoutManager(getActivity()); mPostRecyclerView.setLayoutManager(mLinearLayoutManager); - /*FloatingActionButton fab = rootView.findViewById(R.id.fab_post_fragment); - fab.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) - .setAction("Action", null).show(); - } - });*/ mPostType = getArguments().getInt(POST_TYPE_KEY); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java index 717df7de..b04c10ef 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java @@ -238,7 +238,7 @@ class PostRecyclerViewAdapter extends PagedListAdapter { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditListingFragment.java index c109d767..1972be71 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditListingFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditListingFragment.java @@ -69,7 +69,7 @@ public class SubredditListingFragment extends Fragment implements FragmentCommun // Inflate the layout for this fragment View rootView = inflater.inflate(R.layout.fragment_subreddit_listing, container, false); - ((Infinity) getActivity().getApplication()).getmNetworkComponent().inject(this); + ((Infinity) getActivity().getApplication()).getmAppComponent().inject(this); ButterKnife.bind(this, rootView); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/UserListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/UserListingFragment.java index 832b5140..78153fdc 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/UserListingFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/UserListingFragment.java @@ -76,7 +76,7 @@ public class UserListingFragment extends Fragment implements FragmentCommunicato // Inflate the layout for this fragment View rootView = inflater.inflate(R.layout.fragment_user_listing, container, false); - ((Infinity) getActivity().getApplication()).getmNetworkComponent().inject(this); + ((Infinity) getActivity().getApplication()).getmAppComponent().inject(this); ButterKnife.bind(this, rootView); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java index 8b91b53b..bd57cd48 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java @@ -133,7 +133,7 @@ public class ViewPostDetailActivity extends AppCompatActivity { EventBus.getDefault().register(this); - ((Infinity) getApplication()).getmNetworkComponent().inject(this); + ((Infinity) getApplication()).getmAppComponent().inject(this); getSupportActionBar().setDisplayHomeAsUpEnabled(true); @@ -557,11 +557,11 @@ public class ViewPostDetailActivity extends AppCompatActivity { private SpannableConfiguration getCustomSpannableConfiguration() { return SpannableConfiguration.builder(this).linkResolver((view, link) -> { - if(link.startsWith("/u/")) { + if(link.startsWith("/u/") || link.startsWith("u/")) { Intent intent = new Intent(ViewPostDetailActivity.this, ViewUserDetailActivity.class); intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, link.substring(3)); startActivity(intent); - } else if(link.startsWith("/r/")) { + } else if(link.startsWith("/r/") || link.startsWith("r/")) { Intent intent = new Intent(ViewPostDetailActivity.this, ViewSubredditDetailActivity.class); intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, link.substring(3)); startActivity(intent); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewSubredditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewSubredditDetailActivity.java index 3178a507..d0e45c08 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewSubredditDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewSubredditDetailActivity.java @@ -79,7 +79,7 @@ public class ViewSubredditDetailActivity extends AppCompatActivity { setContentView(R.layout.activity_view_subreddit_detail); ButterKnife.bind(this); - ((Infinity) getApplication()).getmNetworkComponent().inject(this); + ((Infinity) getApplication()).getmAppComponent().inject(this); //Get status bar height int statusBarHeight = 0; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewUserDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewUserDetailActivity.java index 0fb312fb..a55eb6c0 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewUserDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewUserDetailActivity.java @@ -76,7 +76,7 @@ public class ViewUserDetailActivity extends AppCompatActivity { ButterKnife.bind(this); - ((Infinity) getApplication()).getmNetworkComponent().inject(this); + ((Infinity) getApplication()).getmAppComponent().inject(this); //Get status bar height int statusBarHeight = 0; -- cgit v1.2.3