Add two features: refresh searching and searching in SearchActivity. Fixed a bug which is the listener object is null when it is called because the parse failed in ParsePost, ParseSubredditData and ParseUserData.

This commit is contained in:
Alex Ning 2019-02-26 09:27:51 +08:00
parent b1db59fda2
commit 0ea2b24c60
13 changed files with 223 additions and 96 deletions

12
.idea/misc.xml generated
View File

@ -2,10 +2,10 @@
<project version="4"> <project version="4">
<component name="NullableNotNullManager"> <component name="NullableNotNullManager">
<option name="myDefaultNullable" value="android.support.annotation.Nullable" /> <option name="myDefaultNullable" value="android.support.annotation.Nullable" />
<option name="myDefaultNotNull" value="android.support.annotation.NonNull" /> <option name="myDefaultNotNull" value="androidx.annotation.NonNull" />
<option name="myNullables"> <option name="myNullables">
<value> <value>
<list size="7"> <list size="10">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" /> <item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nullable" /> <item index="1" class="java.lang.String" itemvalue="javax.annotation.Nullable" />
<item index="2" class="java.lang.String" itemvalue="javax.annotation.CheckForNull" /> <item index="2" class="java.lang.String" itemvalue="javax.annotation.CheckForNull" />
@ -13,18 +13,24 @@
<item index="4" class="java.lang.String" itemvalue="android.support.annotation.Nullable" /> <item index="4" class="java.lang.String" itemvalue="android.support.annotation.Nullable" />
<item index="5" class="java.lang.String" itemvalue="androidx.annotation.Nullable" /> <item index="5" class="java.lang.String" itemvalue="androidx.annotation.Nullable" />
<item index="6" class="java.lang.String" itemvalue="androidx.annotation.RecentlyNullable" /> <item index="6" class="java.lang.String" itemvalue="androidx.annotation.RecentlyNullable" />
<item index="7" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.qual.Nullable" />
<item index="8" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NullableDecl" />
<item index="9" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NullableType" />
</list> </list>
</value> </value>
</option> </option>
<option name="myNotNulls"> <option name="myNotNulls">
<value> <value>
<list size="6"> <list size="9">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.NotNull" /> <item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.NotNull" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nonnull" /> <item index="1" class="java.lang.String" itemvalue="javax.annotation.Nonnull" />
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.NonNull" /> <item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.NonNull" />
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.NonNull" /> <item index="3" class="java.lang.String" itemvalue="android.support.annotation.NonNull" />
<item index="4" class="java.lang.String" itemvalue="androidx.annotation.NonNull" /> <item index="4" class="java.lang.String" itemvalue="androidx.annotation.NonNull" />
<item index="5" class="java.lang.String" itemvalue="androidx.annotation.RecentlyNonNull" /> <item index="5" class="java.lang.String" itemvalue="androidx.annotation.RecentlyNonNull" />
<item index="6" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.qual.NonNull" />
<item index="7" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NonNullDecl" />
<item index="8" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NonNullType" />
</list> </list>
</value> </value>
</option> </option>

View File

@ -75,8 +75,6 @@ public class MainActivity extends AppCompatActivity {
private boolean mFetchUserInfoSuccess; private boolean mFetchUserInfoSuccess;
private boolean mInsertSuccess; private boolean mInsertSuccess;
private FragmentCommunicator mFragmentCommunicator;
private SubscribedSubredditViewModel mSubscribedSubredditViewModel; private SubscribedSubredditViewModel mSubscribedSubredditViewModel;
private SubscribedUserViewModel mSubscribedUserViewModel; private SubscribedUserViewModel mSubscribedUserViewModel;

View File

@ -37,19 +37,24 @@ class ParsePost {
ParsePostDataAsyncTask(String response, Locale locale, ParsePostDataAsyncTask(String response, Locale locale,
ParsePostListener parsePostListener) { ParsePostListener parsePostListener) {
this.parsePostListener = parsePostListener;
try { try {
jsonResponse = new JSONObject(response); jsonResponse = new JSONObject(response);
this.locale = locale; this.locale = locale;
this.parsePostListener = parsePostListener;
newPosts = new ArrayList<>(); newPosts = new ArrayList<>();
parseFailed = false; parseFailed = false;
} catch (JSONException e) { } catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();
parseFailed = true;
} }
} }
@Override @Override
protected Void doInBackground(Void... voids) { protected Void doInBackground(Void... voids) {
if(parseFailed) {
return null;
}
try { try {
JSONArray allData = jsonResponse.getJSONObject(JSONUtils.DATA_KEY).getJSONArray(JSONUtils.CHILDREN_KEY); JSONArray allData = jsonResponse.getJSONObject(JSONUtils.DATA_KEY).getJSONArray(JSONUtils.CHILDREN_KEY);

View File

@ -116,7 +116,6 @@ class ParseSubredditData {
} catch (JSONException e) { } catch (JSONException e) {
Log.i("subreddit json error", e.getMessage()); Log.i("subreddit json error", e.getMessage());
parseFailed = true; parseFailed = true;
parseSubredditListingDataListener.onParseSubredditListingDataFail();
} }
} }

View File

@ -52,24 +52,6 @@ public class ParseUserData {
protected Void doInBackground(Void... voids) { protected Void doInBackground(Void... voids) {
try { try {
userData = parseUserDataBase(jsonResponse); userData = parseUserDataBase(jsonResponse);
/*jsonResponse = jsonResponse.getJSONObject(JSONUtils.DATA_KEY);
String userName = jsonResponse.getString(JSONUtils.NAME_KEY);
String iconImageUrl = jsonResponse.getString(JSONUtils.ICON_IMG_KEY);
String bannerImageUrl = "";
boolean canBeFollowed;
if(jsonResponse.has(JSONUtils.SUBREDDIT_KEY) && !jsonResponse.isNull(JSONUtils.SUBREDDIT_KEY)) {
bannerImageUrl = jsonResponse.getJSONObject(JSONUtils.SUBREDDIT_KEY).getString(JSONUtils.BANNER_IMG_KEY);
canBeFollowed = true;
} else {
canBeFollowed = false;
}
int linkKarma = jsonResponse.getInt(JSONUtils.LINK_KARMA_KEY);
int commentKarma = jsonResponse.getInt(JSONUtils.COMMENT_KARMA_KEY);
int karma = linkKarma + commentKarma;
boolean isGold = jsonResponse.getBoolean(JSONUtils.IS_GOLD_KEY);
boolean isFriend = jsonResponse.getBoolean(JSONUtils.IS_FRIEND_KEY);
userData = new UserData(userName, iconImageUrl, bannerImageUrl, karma, isGold, isFriend, canBeFollowed);*/
} catch (JSONException e) { } catch (JSONException e) {
parseFailed = true; parseFailed = true;
Log.i("parse user data error", e.getMessage()); Log.i("parse user data error", e.getMessage());
@ -88,6 +70,7 @@ public class ParseUserData {
} }
private static class ParseUserListingDataAsyncTask extends AsyncTask<Void, Void, Void> { private static class ParseUserListingDataAsyncTask extends AsyncTask<Void, Void, Void> {
private String response;
private JSONObject jsonResponse; private JSONObject jsonResponse;
private ParseUserListingDataListener parseUserListingDataListener; private ParseUserListingDataListener parseUserListingDataListener;
private String after; private String after;
@ -96,25 +79,28 @@ public class ParseUserData {
private ArrayList<UserData> userDataArrayList; private ArrayList<UserData> userDataArrayList;
ParseUserListingDataAsyncTask(String response, ParseUserListingDataListener parseUserListingDataListener){ ParseUserListingDataAsyncTask(String response, ParseUserListingDataListener parseUserListingDataListener){
this.parseUserListingDataListener = parseUserListingDataListener;
this.response = response;
try { try {
jsonResponse = new JSONObject(response); jsonResponse = new JSONObject(response);
this.parseUserListingDataListener = parseUserListingDataListener;
parseFailed = false; parseFailed = false;
userDataArrayList = new ArrayList<>(); userDataArrayList = new ArrayList<>();
} catch (JSONException e) { } catch (JSONException e) {
Log.i("userdata json error", e.getMessage()); Log.i("userdata json error", e.getMessage());
this.parseUserListingDataListener.onParseUserListingDataFailed(); parseFailed = true;
} }
} }
@Override @Override
protected Void doInBackground(Void... voids) { protected Void doInBackground(Void... voids) {
try { try {
if(!parseFailed) {
after = jsonResponse.getJSONObject(JSONUtils.DATA_KEY).getString(JSONUtils.AFTER_KEY); after = jsonResponse.getJSONObject(JSONUtils.DATA_KEY).getString(JSONUtils.AFTER_KEY);
JSONArray children = jsonResponse.getJSONObject(JSONUtils.DATA_KEY).getJSONArray(JSONUtils.CHILDREN_KEY); JSONArray children = jsonResponse.getJSONObject(JSONUtils.DATA_KEY).getJSONArray(JSONUtils.CHILDREN_KEY);
for(int i = 0; i < children.length(); i++) { for(int i = 0; i < children.length(); i++) {
userDataArrayList.add(parseUserDataBase(children.getJSONObject(i))); userDataArrayList.add(parseUserDataBase(children.getJSONObject(i)));
} }
}
} catch (JSONException e) { } catch (JSONException e) {
parseFailed = true; parseFailed = true;
Log.i("parse user data error", e.getMessage()); Log.i("parse user data error", e.getMessage());
@ -126,11 +112,15 @@ public class ParseUserData {
protected void onPostExecute(Void aVoid) { protected void onPostExecute(Void aVoid) {
if(!parseFailed) { if(!parseFailed) {
parseUserListingDataListener.onParseUserListingDataSuccess(userDataArrayList, after); parseUserListingDataListener.onParseUserListingDataSuccess(userDataArrayList, after);
} else {
if(response.equals("\"{}\"")) {
parseUserListingDataListener.onParseUserListingDataSuccess(new ArrayList<>(), null);
} else { } else {
parseUserListingDataListener.onParseUserListingDataFailed(); parseUserListingDataListener.onParseUserListingDataFailed();
} }
} }
} }
}
private static UserData parseUserDataBase(JSONObject userDataJson) throws JSONException { private static UserData parseUserDataBase(JSONObject userDataJson) throws JSONException {
userDataJson = userDataJson.getJSONObject(JSONUtils.DATA_KEY); userDataJson = userDataJson.getJSONObject(JSONUtils.DATA_KEY);

View File

@ -2,37 +2,97 @@ package ml.docilealligator.infinityforreddit;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import com.ferfalk.simplesearchview.SimpleSearchView;
import com.google.android.material.tabs.TabLayout; import com.google.android.material.tabs.TabLayout;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter; import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.PagerAdapter;
import androidx.viewpager.widget.ViewPager; import androidx.viewpager.widget.ViewPager;
import butterknife.BindView;
import butterknife.ButterKnife;
public class SearchActivity extends AppCompatActivity { public class SearchActivity extends AppCompatActivity {
static final String QUERY_KEY = "QK"; static final String QUERY_KEY = "QK";
private String mQuery; private String mQuery;
@BindView(R.id.toolbar_search_activity) Toolbar toolbar;
@BindView(R.id.search_view_search_activity) SimpleSearchView simpleSearchView;
@BindView(R.id.tab_layout_search_activity) TabLayout tabLayout;
@BindView(R.id.transparent_overlay_search_activity) View transparentOverlay;
@BindView(R.id.view_pager_search_activity) ViewPager viewPager;
private SectionsPagerAdapter sectionsPagerAdapter;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_search); setContentView(R.layout.activity_search);
ButterKnife.bind(this);
Toolbar toolbar = findViewById(R.id.toolbar_search_activity);
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
ViewPager viewPager = findViewById(R.id.view_pager_search_activity); sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
PagerAdapter pagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); viewPager.setAdapter(sectionsPagerAdapter);
viewPager.setAdapter(pagerAdapter); viewPager.setOffscreenPageLimit(2);
TabLayout tabLayout = findViewById(R.id.tab_layout_search_activity);
tabLayout.setupWithViewPager(viewPager); tabLayout.setupWithViewPager(viewPager);
transparentOverlay.setOnClickListener(view -> simpleSearchView.onBackPressed());
simpleSearchView.setOnQueryTextListener(new SimpleSearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
Intent intent = getIntent();
intent.putExtra(SearchActivity.QUERY_KEY, query);
finish();
startActivity(intent);
overridePendingTransition(0, 0);
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
return false;
}
@Override
public boolean onQueryTextCleared() {
return false;
}
});
simpleSearchView.setOnSearchViewListener(new SimpleSearchView.SearchViewListener() {
@Override
public void onSearchViewShown() {
transparentOverlay.setVisibility(View.VISIBLE);
}
@Override
public void onSearchViewClosed() {
transparentOverlay.setVisibility(View.GONE);
}
@Override
public void onSearchViewShownAnimation() {
}
@Override
public void onSearchViewClosedAnimation() {
}
});
// Get the intent, verify the action and get the query // Get the intent, verify the action and get the query
Intent intent = getIntent(); Intent intent = getIntent();
String query = intent.getExtras().getString(QUERY_KEY); String query = intent.getExtras().getString(QUERY_KEY);
@ -42,22 +102,55 @@ public class SearchActivity extends AppCompatActivity {
} }
} }
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (simpleSearchView.onActivityResult(requestCode, resultCode, data)) {
return;
}
super.onActivityResult(requestCode, resultCode, data);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main_activity, menu);
simpleSearchView.setMenuItem(menu.findItem(R.id.action_search_main_activity));
return true;
}
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) { switch (item.getItemId()) {
case android.R.id.home: case android.R.id.home:
onBackPressed(); onBackPressed();
return true; return true;
case R.id.action_refresh_main_activity:
sectionsPagerAdapter.refresh();
return true;
} }
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }
@Override
public void onBackPressed() {
if (simpleSearchView.onBackPressed()) {
return;
}
super.onBackPressed();
}
public class SectionsPagerAdapter extends FragmentPagerAdapter { public class SectionsPagerAdapter extends FragmentPagerAdapter {
private PostFragment postFragment;
private SubredditListingFragment subredditListingFragment;
private UserListingFragment userListingFragment;
public SectionsPagerAdapter(FragmentManager fm) { public SectionsPagerAdapter(FragmentManager fm) {
super(fm); super(fm);
} }
@NonNull
@Override @Override
public Fragment getItem(int position) { public Fragment getItem(int position) {
switch (position) { switch (position) {
@ -104,5 +197,41 @@ public class SearchActivity extends AppCompatActivity {
} }
return null; return null;
} }
@NonNull
@Override
public Object instantiateItem(@NonNull ViewGroup container, int position) {
Fragment fragment = (Fragment) super.instantiateItem(container, position);
switch (position) {
case 0:
postFragment = (PostFragment) fragment;
break;
case 1:
subredditListingFragment = (SubredditListingFragment) fragment;
break;
case 2:
userListingFragment = (UserListingFragment) fragment;
break;
}
return fragment;
}
public void refresh() {
if(postFragment != null) {
((FragmentCommunicator) postFragment).refresh();
}
if(subredditListingFragment != null) {
((FragmentCommunicator) subredditListingFragment).refresh();
}
if (userListingFragment != null) {
((FragmentCommunicator) userListingFragment).refresh();
}
}
public void newSearch() {
getItem(0);
getItem(1);
getItem(2);
}
} }
} }

View File

@ -24,7 +24,7 @@ public class SubredditListingDataSourceFactory extends DataSource.Factory {
@NonNull @NonNull
@Override @Override
public DataSource create() { public DataSource create() {
SubredditListingDataSource subredditListingDataSource = new SubredditListingDataSource(retrofit, subredditListingDataSource = new SubredditListingDataSource(retrofit,
query, onSubredditListingDataFetchedCallback); query, onSubredditListingDataFetchedCallback);
subredditListingDataSourceMutableLiveData.postValue(subredditListingDataSource); subredditListingDataSourceMutableLiveData.postValue(subredditListingDataSource);
return subredditListingDataSource; return subredditListingDataSource;

View File

@ -1,7 +1,6 @@
package ml.docilealligator.infinityforreddit; package ml.docilealligator.infinityforreddit;
import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@ -31,7 +30,7 @@ import retrofit2.Retrofit;
/** /**
* A simple {@link Fragment} subclass. * A simple {@link Fragment} subclass.
*/ */
public class SubredditListingFragment extends Fragment { public class SubredditListingFragment extends Fragment implements FragmentCommunicator {
static final String QUERY_KEY = "QK"; static final String QUERY_KEY = "QK";
@ -79,9 +78,6 @@ public class SubredditListingFragment extends Fragment {
mQuery = getArguments().getString(QUERY_KEY); mQuery = getArguments().getString(QUERY_KEY);
String accessToken = getActivity().getSharedPreferences(SharedPreferencesUtils.AUTH_CODE_FILE_KEY, Context.MODE_PRIVATE)
.getString(SharedPreferencesUtils.ACCESS_TOKEN_KEY, "");
SubredditListingViewModel.Factory factory = new SubredditListingViewModel.Factory(mRetrofit, mQuery, SubredditListingViewModel.Factory factory = new SubredditListingViewModel.Factory(mRetrofit, mQuery,
new SubredditListingDataSource.OnSubredditListingDataFetchedCallback() { new SubredditListingDataSource.OnSubredditListingDataFetchedCallback() {
@Override @Override
@ -116,7 +112,7 @@ public class SubredditListingFragment extends Fragment {
mProgressBar.setVisibility(View.GONE); mProgressBar.setVisibility(View.GONE);
} else if(networkState.getStatus().equals(NetworkState.Status.FAILED)) { } else if(networkState.getStatus().equals(NetworkState.Status.FAILED)) {
mFetchSubredditListingInfoLinearLayout.setOnClickListener(view -> mSubredditListingViewModel.retry()); mFetchSubredditListingInfoLinearLayout.setOnClickListener(view -> mSubredditListingViewModel.retry());
showErrorView(R.string.load_posts_error); showErrorView(R.string.search_subreddits_error);
} else { } else {
mFetchSubredditListingInfoLinearLayout.setVisibility(View.GONE); mFetchSubredditListingInfoLinearLayout.setVisibility(View.GONE);
mProgressBar.setVisibility(View.VISIBLE); mProgressBar.setVisibility(View.VISIBLE);
@ -138,4 +134,9 @@ public class SubredditListingFragment extends Fragment {
Glide.with(this).load(R.drawable.load_post_error_indicator).into(mFetchSubredditListingInfoImageView); Glide.with(this).load(R.drawable.load_post_error_indicator).into(mFetchSubredditListingInfoImageView);
} }
} }
@Override
public void refresh() {
mSubredditListingViewModel.refresh();
}
} }

View File

@ -10,31 +10,31 @@ public class UserListingDataSourceFactory extends DataSource.Factory {
private String query; private String query;
private UserListingDataSource.OnUserListingDataFetchedCallback onUserListingDataFetchedCallback; private UserListingDataSource.OnUserListingDataFetchedCallback onUserListingDataFetchedCallback;
private UserListingDataSource UserListingDataSource; private UserListingDataSource userListingDataSource;
private MutableLiveData<UserListingDataSource> UserListingDataSourceMutableLiveData; private MutableLiveData<UserListingDataSource> userListingDataSourceMutableLiveData;
UserListingDataSourceFactory(Retrofit retrofit, String query, UserListingDataSourceFactory(Retrofit retrofit, String query,
UserListingDataSource.OnUserListingDataFetchedCallback onUserListingDataFetchedCallback) { UserListingDataSource.OnUserListingDataFetchedCallback onUserListingDataFetchedCallback) {
this.retrofit = retrofit; this.retrofit = retrofit;
this.query = query; this.query = query;
this.onUserListingDataFetchedCallback = onUserListingDataFetchedCallback; this.onUserListingDataFetchedCallback = onUserListingDataFetchedCallback;
UserListingDataSourceMutableLiveData = new MutableLiveData<>(); userListingDataSourceMutableLiveData = new MutableLiveData<>();
} }
@NonNull @NonNull
@Override @Override
public DataSource create() { public DataSource create() {
UserListingDataSource UserListingDataSource = new UserListingDataSource(retrofit, userListingDataSource = new UserListingDataSource(retrofit,
query, onUserListingDataFetchedCallback); query, onUserListingDataFetchedCallback);
UserListingDataSourceMutableLiveData.postValue(UserListingDataSource); userListingDataSourceMutableLiveData.postValue(userListingDataSource);
return UserListingDataSource; return userListingDataSource;
} }
public MutableLiveData<UserListingDataSource> getUserListingDataSourceMutableLiveData() { public MutableLiveData<UserListingDataSource> getUserListingDataSourceMutableLiveData() {
return UserListingDataSourceMutableLiveData; return userListingDataSourceMutableLiveData;
} }
UserListingDataSource getUserListingDataSource() { UserListingDataSource getUserListingDataSource() {
return UserListingDataSource; return userListingDataSource;
} }
} }

View File

@ -31,7 +31,7 @@ import retrofit2.Retrofit;
/** /**
* A simple {@link Fragment} subclass. * A simple {@link Fragment} subclass.
*/ */
public class UserListingFragment extends Fragment { public class UserListingFragment extends Fragment implements FragmentCommunicator {
static final String QUERY_KEY = "QK"; static final String QUERY_KEY = "QK";
@BindView(R.id.coordinator_layout_user_listing_fragment) @BindView(R.id.coordinator_layout_user_listing_fragment)
@ -122,7 +122,7 @@ public class UserListingFragment extends Fragment {
mProgressBar.setVisibility(View.GONE); mProgressBar.setVisibility(View.GONE);
} else if(networkState.getStatus().equals(NetworkState.Status.FAILED)) { } else if(networkState.getStatus().equals(NetworkState.Status.FAILED)) {
mFetchUserListingInfoLinearLayout.setOnClickListener(view -> mUserListingViewModel.retry()); mFetchUserListingInfoLinearLayout.setOnClickListener(view -> mUserListingViewModel.retry());
showErrorView(R.string.load_posts_error); showErrorView(R.string.search_users_error);
} else { } else {
mFetchUserListingInfoLinearLayout.setVisibility(View.GONE); mFetchUserListingInfoLinearLayout.setVisibility(View.GONE);
mProgressBar.setVisibility(View.VISIBLE); mProgressBar.setVisibility(View.VISIBLE);
@ -144,4 +144,9 @@ public class UserListingFragment extends Fragment {
Glide.with(this).load(R.drawable.load_post_error_indicator).into(mFetchUserListingInfoImageView); Glide.with(this).load(R.drawable.load_post_error_indicator).into(mFetchUserListingInfoImageView);
} }
} }
@Override
public void refresh() {
mUserListingViewModel.refresh();
}
} }

View File

@ -293,40 +293,4 @@ public class ViewUserDetailActivity extends AppCompatActivity {
return null; return null;
} }
} }
/*private static class CheckIsFollowingUserAsyncTask extends AsyncTask<Void, Void, Void> {
private SubscribedUserDao subscribedUserDao;
private String userName;
private SubscribedUserData subscribedUserData;
private CheckIsFollowingUserListener checkIsFollowingUserListener;
interface CheckIsFollowingUserListener {
void isSubscribed();
void isNotSubscribed();
}
CheckIsFollowingUserAsyncTask(SubscribedUserDao subscribedUserDao, String userName,
CheckIsFollowingUserListener checkIsFollowingUserListener) {
this.subscribedUserDao = subscribedUserDao;
this.userName = userName;
this.checkIsFollowingUserListener = checkIsFollowingUserListener;
}
@Override
protected Void doInBackground(Void... voids) {
subscribedUserData = subscribedUserDao.getSubscribedUser(userName);
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
if(subscribedUserData != null) {
checkIsFollowingUserListener.isSubscribed();
} else {
checkIsFollowingUserListener.isNotSubscribed();
}
}
}*/
} }

View File

@ -11,6 +11,10 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay"> android:theme="@style/AppTheme.AppBarOverlay">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.appcompat.widget.Toolbar <androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar_search_activity" android:id="@+id/toolbar_search_activity"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -18,6 +22,22 @@
android:background="?attr/colorPrimary" android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" /> app:popupTheme="@style/AppTheme.PopupOverlay" />
<com.ferfalk.simplesearchview.SimpleSearchView
android:id="@+id/search_view_search_activity"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textColor="@android:color/white"
app:voiceSearch="true"
app:searchBackground="@color/colorPrimary"
app:cursorColor="@android:color/white"
app:hintColor="#E0E0E0"
app:iconsTint="@android:color/white"
app:backIconTint="@android:color/white"
app:iconsAlpha="1"
app:backIconAlpha="1" />
</FrameLayout>
<com.google.android.material.tabs.TabLayout <com.google.android.material.tabs.TabLayout
android:id="@+id/tab_layout_search_activity" android:id="@+id/tab_layout_search_activity"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -34,6 +54,14 @@
</com.google.android.material.appbar.AppBarLayout> </com.google.android.material.appbar.AppBarLayout>
<View
android:id="@+id/transparent_overlay_search_activity"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#40000000"
android:elevation="1dp"
android:visibility="gone"/>
<androidx.viewpager.widget.ViewPager <androidx.viewpager.widget.ViewPager
android:id="@+id/view_pager_search_activity" android:id="@+id/view_pager_search_activity"
android:layout_width="match_parent" android:layout_width="match_parent"

View File

@ -13,6 +13,8 @@
<string name="tap_to_retry">Error loading image. Tap to retry.</string> <string name="tap_to_retry">Error loading image. Tap to retry.</string>
<string name="load_posts_error">Error loading posts.\nTap to retry.</string> <string name="load_posts_error">Error loading posts.\nTap to retry.</string>
<string name="search_subreddits_error">Error searching subreddits.\nTap to retry.</string>
<string name="search_users_error">Error searching users.\nTap to retry.</string>
<string name="no_posts">No posts found.</string> <string name="no_posts">No posts found.</string>
<string name="no_subreddits">No subreddits found.</string> <string name="no_subreddits">No subreddits found.</string>
<string name="no_users">No users found.</string> <string name="no_users">No users found.</string>