1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-11-24 23:57:30 +00:00
This commit is contained in:
Austin Huang 2021-02-07 17:45:16 -05:00
parent 3baa82090e
commit 28b74a6975
No known key found for this signature in database
GPG Key ID: 84C23AA04587A91F
14 changed files with 88 additions and 101 deletions

View File

@ -62,7 +62,7 @@ dependencies {
def nav_version = '2.3.2' def nav_version = '2.3.2'
def exoplayer_version = '2.12.0' def exoplayer_version = '2.12.0'
implementation 'com.google.android.material:material:1.3.0-beta01' implementation 'com.google.android.material:material:1.3.0'
implementation "com.google.android.exoplayer:exoplayer-core:$exoplayer_version" implementation "com.google.android.exoplayer:exoplayer-core:$exoplayer_version"
implementation "com.google.android.exoplayer:exoplayer-dash:$exoplayer_version" implementation "com.google.android.exoplayer:exoplayer-dash:$exoplayer_version"

View File

@ -15,7 +15,7 @@ import awais.instagrabber.webservices.GraphQLService;
import awais.instagrabber.webservices.ServiceCallback; import awais.instagrabber.webservices.ServiceCallback;
import awais.instagrabber.webservices.UserService; import awais.instagrabber.webservices.UserService;
public final class ProfileFetcher extends AsyncTask<Void, Void, String> { public final class ProfileFetcher extends AsyncTask<Void, Void, Void> {
private static final String TAG = ProfileFetcher.class.getSimpleName(); private static final String TAG = ProfileFetcher.class.getSimpleName();
private final UserService userService; private final UserService userService;
private final GraphQLService graphQLService; private final GraphQLService graphQLService;
@ -36,12 +36,11 @@ public final class ProfileFetcher extends AsyncTask<Void, Void, String> {
@Nullable @Nullable
@Override @Override
protected String doInBackground(final Void... voids) { protected Void doInBackground(final Void... voids) {
if (isLoggedIn) { if (isLoggedIn) {
userService.getUsernameInfo(userName, new ServiceCallback<User>() { userService.getUsernameInfo(userName, new ServiceCallback<User>() {
@Override @Override
public void onSuccess(final User user) { public void onSuccess(final User user) {
Log.d("austin_debug", user.getUsername() + " " + userName);
userService.getUserFriendship(user.getPk(), new ServiceCallback<FriendshipStatus>() { userService.getUserFriendship(user.getPk(), new ServiceCallback<FriendshipStatus>() {
@Override @Override
public void onSuccess(final FriendshipStatus status) { public void onSuccess(final FriendshipStatus status) {
@ -52,6 +51,7 @@ public final class ProfileFetcher extends AsyncTask<Void, Void, String> {
@Override @Override
public void onFailure(final Throwable t) { public void onFailure(final Throwable t) {
Log.e(TAG, "Error", t); Log.e(TAG, "Error", t);
fetchListener.onFailure(t);
} }
}); });
} }
@ -59,6 +59,7 @@ public final class ProfileFetcher extends AsyncTask<Void, Void, String> {
@Override @Override
public void onFailure(final Throwable t) { public void onFailure(final Throwable t) {
Log.e(TAG, "Error", t); Log.e(TAG, "Error", t);
fetchListener.onFailure(t);
} }
}); });
} }
@ -72,10 +73,11 @@ public final class ProfileFetcher extends AsyncTask<Void, Void, String> {
@Override @Override
public void onFailure(final Throwable t) { public void onFailure(final Throwable t) {
Log.e(TAG, "Error", t); Log.e(TAG, "Error", t);
fetchListener.onFailure(t);
} }
}); });
} }
return "yeah"; return null;
} }
@Override @Override

View File

@ -127,7 +127,10 @@ public class ProfilePicDialogFragment extends DialogFragment {
@Override @Override
public void onFailure(final Throwable t) { public void onFailure(final Throwable t) {
final Context context = getContext(); final Context context = getContext();
Toast.makeText(context, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show(); try {
Toast.makeText(context, t.getMessage(), Toast.LENGTH_SHORT).show();
}
catch(final Throwable e) {}
getDialog().dismiss(); getDialog().dismiss();
} }
}); });

View File

@ -307,8 +307,11 @@ public class CollectionPostsFragment extends Fragment implements SwipeRefreshLay
@Override @Override
public void onFailure(final Throwable t) { public void onFailure(final Throwable t) {
Log.e(TAG, "Error deleting collection", t); Log.e(TAG, "Error deleting collection", t);
try {
Toast.makeText(context, t.getMessage(), Toast.LENGTH_SHORT).show(); Toast.makeText(context, t.getMessage(), Toast.LENGTH_SHORT).show();
} }
catch(final Throwable e) {}
}
}); });
}) })
.setNegativeButton(R.string.cancel, null) .setNegativeButton(R.string.cancel, null)
@ -334,8 +337,11 @@ public class CollectionPostsFragment extends Fragment implements SwipeRefreshLay
@Override @Override
public void onFailure(final Throwable t) { public void onFailure(final Throwable t) {
Log.e(TAG, "Error editing collection", t); Log.e(TAG, "Error editing collection", t);
try {
Toast.makeText(context, t.getMessage(), Toast.LENGTH_SHORT).show(); Toast.makeText(context, t.getMessage(), Toast.LENGTH_SHORT).show();
} }
catch(final Throwable e) {}
}
}); });
}) })
.setNegativeButton(R.string.cancel, null) .setNegativeButton(R.string.cancel, null)

View File

@ -371,8 +371,11 @@ public final class CommentsViewerFragment extends BottomSheetDialogFragment impl
@Override @Override
public void onFailure(final Throwable t) { public void onFailure(final Throwable t) {
Log.e(TAG, "Error liking comment", t); Log.e(TAG, "Error liking comment", t);
try {
Toast.makeText(context, t.getMessage(), Toast.LENGTH_SHORT).show(); Toast.makeText(context, t.getMessage(), Toast.LENGTH_SHORT).show();
} }
catch(final Throwable e) {}
}
}); });
return; return;
} }
@ -389,8 +392,11 @@ public final class CommentsViewerFragment extends BottomSheetDialogFragment impl
@Override @Override
public void onFailure(final Throwable t) { public void onFailure(final Throwable t) {
Log.e(TAG, "Error unliking comment", t); Log.e(TAG, "Error unliking comment", t);
try {
Toast.makeText(context, t.getMessage(), Toast.LENGTH_SHORT).show(); Toast.makeText(context, t.getMessage(), Toast.LENGTH_SHORT).show();
} }
catch(final Throwable e) {}
}
}); });
break; break;
case 5: // translate comment case 5: // translate comment
@ -411,8 +417,11 @@ public final class CommentsViewerFragment extends BottomSheetDialogFragment impl
@Override @Override
public void onFailure(final Throwable t) { public void onFailure(final Throwable t) {
Log.e(TAG, "Error translating comment", t); Log.e(TAG, "Error translating comment", t);
try {
Toast.makeText(context, t.getMessage(), Toast.LENGTH_SHORT).show(); Toast.makeText(context, t.getMessage(), Toast.LENGTH_SHORT).show();
} }
catch(final Throwable e) {}
}
}); });
break; break;
case 6: // delete comment case 6: // delete comment
@ -432,8 +441,11 @@ public final class CommentsViewerFragment extends BottomSheetDialogFragment impl
@Override @Override
public void onFailure(final Throwable t) { public void onFailure(final Throwable t) {
Log.e(TAG, "Error deleting comment", t); Log.e(TAG, "Error deleting comment", t);
try {
Toast.makeText(context, t.getMessage(), Toast.LENGTH_SHORT).show(); Toast.makeText(context, t.getMessage(), Toast.LENGTH_SHORT).show();
} }
catch(final Throwable e) {}
}
}); });
break; break;
} }

View File

@ -44,7 +44,7 @@ public final class FollowViewerFragment extends Fragment implements SwipeRefresh
private final ArrayList<FollowModel> followersModels = new ArrayList<>(); private final ArrayList<FollowModel> followersModels = new ArrayList<>();
private final ArrayList<FollowModel> allFollowing = new ArrayList<>(); private final ArrayList<FollowModel> allFollowing = new ArrayList<>();
private boolean moreAvailable = true, isFollowersList, isCompare = false, loading = false, shouldRefresh = true; private boolean moreAvailable = true, isFollowersList, isCompare = false, loading = false, shouldRefresh = true, searching = false;
private long profileId; private long profileId;
private String username; private String username;
private String namePost; private String namePost;
@ -65,7 +65,7 @@ public final class FollowViewerFragment extends Fragment implements SwipeRefresh
final ServiceCallback<FriendshipListFetchResponse> followingFetchCb = new ServiceCallback<FriendshipListFetchResponse>() { final ServiceCallback<FriendshipListFetchResponse> followingFetchCb = new ServiceCallback<FriendshipListFetchResponse>() {
@Override @Override
public void onSuccess(final FriendshipListFetchResponse result) { public void onSuccess(final FriendshipListFetchResponse result) {
if (result != null) { if (result != null && isCompare) {
followingModels.addAll(result.getItems()); followingModels.addAll(result.getItems());
if (!isFollowersList) followModels.addAll(result.getItems()); if (!isFollowersList) followModels.addAll(result.getItems());
if (result.isMoreAvailable()) { if (result.isMoreAvailable()) {
@ -78,7 +78,7 @@ public final class FollowViewerFragment extends Fragment implements SwipeRefresh
if (!isFollowersList) moreAvailable = false; if (!isFollowersList) moreAvailable = false;
showCompare(); showCompare();
} }
} else binding.swipeRefreshLayout.setRefreshing(false); } else if (isCompare) binding.swipeRefreshLayout.setRefreshing(false);
} }
@Override @Override
@ -94,7 +94,7 @@ public final class FollowViewerFragment extends Fragment implements SwipeRefresh
final ServiceCallback<FriendshipListFetchResponse> followersFetchCb = new ServiceCallback<FriendshipListFetchResponse>() { final ServiceCallback<FriendshipListFetchResponse> followersFetchCb = new ServiceCallback<FriendshipListFetchResponse>() {
@Override @Override
public void onSuccess(final FriendshipListFetchResponse result) { public void onSuccess(final FriendshipListFetchResponse result) {
if (result != null) { if (result != null && isCompare) {
followersModels.addAll(result.getItems()); followersModels.addAll(result.getItems());
if (isFollowersList) followModels.addAll(result.getItems()); if (isFollowersList) followModels.addAll(result.getItems());
if (result.isMoreAvailable()) { if (result.isMoreAvailable()) {
@ -107,7 +107,7 @@ public final class FollowViewerFragment extends Fragment implements SwipeRefresh
if (isFollowersList) moreAvailable = false; if (isFollowersList) moreAvailable = false;
showCompare(); showCompare();
} }
} } else if (isCompare) binding.swipeRefreshLayout.setRefreshing(false);
} }
@Override @Override
@ -237,12 +237,12 @@ public final class FollowViewerFragment extends Fragment implements SwipeRefresh
}; };
layoutManager = new LinearLayoutManager(getContext()); layoutManager = new LinearLayoutManager(getContext());
lazyLoader = new RecyclerLazyLoader(layoutManager, (page, totalItemsCount) -> { lazyLoader = new RecyclerLazyLoader(layoutManager, (page, totalItemsCount) -> {
if (!TextUtils.isEmpty(endCursor)) { if (!TextUtils.isEmpty(endCursor) && !searching) {
binding.swipeRefreshLayout.setRefreshing(true); binding.swipeRefreshLayout.setRefreshing(true);
layoutManager.setStackFromEnd(true); layoutManager.setStackFromEnd(true);
friendshipService.getList(isFollowersList, profileId, endCursor, cb); friendshipService.getList(isFollowersList, profileId, endCursor, cb);
}
endCursor = null; endCursor = null;
}
}); });
binding.rvFollow.addOnScrollListener(lazyLoader); binding.rvFollow.addOnScrollListener(lazyLoader);
binding.rvFollow.setLayoutManager(layoutManager); binding.rvFollow.setLayoutManager(layoutManager);
@ -303,68 +303,6 @@ public final class FollowViewerFragment extends Fragment implements SwipeRefresh
final SearchView searchView = (SearchView) menuSearch.getActionView(); final SearchView searchView = (SearchView) menuSearch.getActionView();
searchView.setQueryHint(getResources().getString(R.string.action_search)); searchView.setQueryHint(getResources().getString(R.string.action_search));
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
// private final Filter filter = new Filter() {
// private final ArrayList<FollowModel> searchFollowModels = new ArrayList<>(followModels.size() / 2);
// private final ArrayList<FollowModel> searchFollowingModels = new ArrayList<>(followingModels.size() / 2);
// private final ArrayList<FollowModel> searchFollowersModels = new ArrayList<>(followersModels.size() / 2);
// private final ArrayList<FollowModel> searchAllFollowing = new ArrayList<>(allFollowing.size() / 2);
//
// @Nullable
// @Override
// protected FilterResults performFiltering(@NonNull final CharSequence constraint) {
// searchFollowModels.clear();
// searchFollowingModels.clear();
// searchFollowersModels.clear();
// searchAllFollowing.clear();
//
// final int followModelsSize = followModels.size();
// final int followingModelsSize = followingModels.size();
// final int followersModelsSize = followersModels.size();
// final int allFollowingSize = allFollowing.size();
//
// int maxSize = followModelsSize;
// if (maxSize < followingModelsSize) maxSize = followingModelsSize;
// if (maxSize < followersModelsSize) maxSize = followersModelsSize;
// if (maxSize < allFollowingSize) maxSize = allFollowingSize;
//
// final String query = constraint.toString().toLowerCase();
// FollowModel followModel;
// while (maxSize != -1) {
// if (maxSize < followModelsSize) {
// followModel = followModels.get(maxSize);
// if (Utils.hasKey(query, followModel.getUsername(), followModel.getFullName()))
// searchFollowModels.add(followModel);
// }
//
// if (maxSize < followingModelsSize) {
// followModel = followingModels.get(maxSize);
// if (Utils.hasKey(query, followModel.getUsername(), followModel.getFullName()))
// searchFollowingModels.add(followModel);
// }
//
// if (maxSize < followersModelsSize) {
// followModel = followersModels.get(maxSize);
// if (Utils.hasKey(query, followModel.getUsername(), followModel.getFullName()))
// searchFollowersModels.add(followModel);
// }
//
// if (maxSize < allFollowingSize) {
// followModel = allFollowing.get(maxSize);
// if (Utils.hasKey(query, followModel.getUsername(), followModel.getFullName()))
// searchAllFollowing.add(followModel);
// }
//
// --maxSize;
// }
//
// return null;
// }
//
// @Override
// protected void publishResults(final CharSequence query, final FilterResults results) {
// refreshAdapter(searchFollowModels, searchFollowingModels, searchFollowersModels, searchAllFollowing);
// }
// };
@Override @Override
public boolean onQueryTextSubmit(final String query) { public boolean onQueryTextSubmit(final String query) {
@ -373,9 +311,15 @@ public final class FollowViewerFragment extends Fragment implements SwipeRefresh
@Override @Override
public boolean onQueryTextChange(final String query) { public boolean onQueryTextChange(final String query) {
// if (Utils.isEmpty(query)) refreshAdapter(followModels, followingModels, followersModels, allFollowing); if (TextUtils.isEmpty(query)) {
searching = false;
// refreshAdapter(followModels, followingModels, followersModels, allFollowing);
}
// else filter.filter(query.toLowerCase()); // else filter.filter(query.toLowerCase());
if (adapter != null) adapter.getFilter().filter(query); if (adapter != null) {
searching = true;
adapter.getFilter().filter(query);
}
return true; return true;
} }
}); });

View File

@ -376,7 +376,8 @@ public class HashTagFragment extends Fragment implements SwipeRefreshLayout.OnRe
final Context context = getContext(); final Context context = getContext();
if (context == null) return; if (context == null) return;
if (hashtagModel == null) { if (hashtagModel == null) {
Toast.makeText(context, R.string.error_loading_profile, Toast.LENGTH_SHORT).show(); Toast.makeText(context, R.string.error_loading_hashtag, Toast.LENGTH_SHORT).show();
binding.swipeRefreshLayout.setEnabled(false);
return; return;
} }
setTitle(); setTitle();

View File

@ -385,7 +385,8 @@ public class LocationFragment extends Fragment implements SwipeRefreshLayout.OnR
if (locationModel == null) { if (locationModel == null) {
final Context context = getContext(); final Context context = getContext();
if (context == null) return; if (context == null) return;
Toast.makeText(context, R.string.error_loading_profile, Toast.LENGTH_SHORT).show(); Toast.makeText(context, R.string.error_loading_location, Toast.LENGTH_SHORT).show();
binding.swipeRefreshLayout.setEnabled(false);
return; return;
} }
setTitle(); setTitle();

View File

@ -538,10 +538,26 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
private void fetchProfileDetails() { private void fetchProfileDetails() {
if (TextUtils.isEmpty(username)) return; if (TextUtils.isEmpty(username)) return;
new ProfileFetcher(username.trim().substring(1), isLoggedIn, profileModel -> { new ProfileFetcher(username.trim().substring(1), isLoggedIn, new FetchListener<User>() {
@Override
public void onResult(final User user) {
if (getContext() == null) return; if (getContext() == null) return;
this.profileModel = profileModel; profileModel = user;
setProfileDetails(); setProfileDetails();
}
@Override
public void onFailure(final Throwable t) {
Log.e(TAG, "Error fetching profile", t);
final Context context = getContext();
try {
if (t == null) Toast.makeText(context,
isLoggedIn ? R.string.error_loading_profile_loggedin : R.string.error_loading_profile,
Toast.LENGTH_LONG).show();
else Toast.makeText(context, t.getMessage(), Toast.LENGTH_SHORT).show();
}
catch(final Throwable e) {}
}
}).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); }).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} }
@ -902,7 +918,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
@Override @Override
public void onSuccess(final FriendshipChangeResponse result) { public void onSuccess(final FriendshipChangeResponse result) {
// Log.d(TAG, "Unfollow success: " + result); // Log.d(TAG, "Unfollow success: " + result);
onRefresh(); fetchProfileDetails();
} }
@Override @Override
@ -920,7 +936,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
@Override @Override
public void onSuccess(final FriendshipChangeResponse result) { public void onSuccess(final FriendshipChangeResponse result) {
// Log.d(TAG, "Unfollow success: " + result); // Log.d(TAG, "Unfollow success: " + result);
onRefresh(); fetchProfileDetails();
} }
@Override @Override
@ -935,7 +951,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
@Override @Override
public void onSuccess(final FriendshipChangeResponse result) { public void onSuccess(final FriendshipChangeResponse result) {
// Log.d(TAG, "Follow success: " + result); // Log.d(TAG, "Follow success: " + result);
onRefresh(); fetchProfileDetails();
} }
@Override @Override

View File

@ -64,7 +64,7 @@ public class MorePreferencesFragment extends BasePreferencesFragment {
screen.addPreference(accountCategory); screen.addPreference(accountCategory);
if (isLoggedIn) { if (isLoggedIn) {
accountCategory.setSummary(R.string.account_hint); accountCategory.setSummary(R.string.account_hint);
accountCategory.addPreference(getAccountSwitcherPreference(cookie)); accountCategory.addPreference(getAccountSwitcherPreference(cookie, context));
accountCategory.addPreference(getPreference(R.string.logout, R.string.logout_summary, R.drawable.ic_logout_24, preference -> { accountCategory.addPreference(getPreference(R.string.logout, R.string.logout_summary, R.drawable.ic_logout_24, preference -> {
if (getContext() == null) return false; if (getContext() == null) return false;
CookieUtils.setupCookies("LOGOUT"); CookieUtils.setupCookies("LOGOUT");
@ -79,7 +79,7 @@ public class MorePreferencesFragment extends BasePreferencesFragment {
public void onSuccess(@NonNull final List<Account> accounts) { public void onSuccess(@NonNull final List<Account> accounts) {
if (!isLoggedIn) { if (!isLoggedIn) {
if (accounts.size() > 0) { if (accounts.size() > 0) {
accountCategory.addPreference(getAccountSwitcherPreference(null)); accountCategory.addPreference(getAccountSwitcherPreference(null, context));
} }
// Need to show something to trigger login activity // Need to show something to trigger login activity
accountCategory.addPreference(getPreference(R.string.add_account, R.drawable.ic_add, preference -> { accountCategory.addPreference(getPreference(R.string.add_account, R.drawable.ic_add, preference -> {
@ -235,8 +235,7 @@ public class MorePreferencesFragment extends BasePreferencesFragment {
} }
} }
private AccountSwitcherPreference getAccountSwitcherPreference(final String cookie) { private AccountSwitcherPreference getAccountSwitcherPreference(final String cookie, final Context context) {
final Context context = getContext();
if (context == null) return null; if (context == null) return null;
return new AccountSwitcherPreference(context, cookie, accountRepository, v -> showAccountSwitcherDialog()); return new AccountSwitcherPreference(context, cookie, accountRepository, v -> showAccountSwitcherDialog());
} }

View File

@ -62,7 +62,7 @@ public class UserService extends BaseService {
public void onResponse(@NonNull final Call<WrappedUser> call, @NonNull final Response<WrappedUser> response) { public void onResponse(@NonNull final Call<WrappedUser> call, @NonNull final Response<WrappedUser> response) {
final WrappedUser user = response.body(); final WrappedUser user = response.body();
if (user == null) { if (user == null) {
callback.onSuccess(null); callback.onFailure(null);
return; return;
} }
callback.onSuccess(user.getUser()); callback.onSuccess(user.getUser());

View File

@ -36,7 +36,10 @@
<string name="dm_mark_as_seen_setting_summary">Other members will know you viewed it</string> <string name="dm_mark_as_seen_setting_summary">Other members will know you viewed it</string>
<string name="activity_setting">Enable activity notifications</string> <string name="activity_setting">Enable activity notifications</string>
<string name="story_sort_setting">Feed stories sort</string> <string name="story_sort_setting">Feed stories sort</string>
<string name="error_loading_profile">Error loading profile!\nTry logging in and search again.</string> <string name="error_loading_profile">Error loading profile! Is the username valid? If so, you may be ratelimited.</string>
<string name="error_loading_profile_loggedin">Error loading profile! Is the username valid? Or did they block you?</string>
<string name="error_loading_hashtag">Error loading hashtag! Is the name valid?</string>
<string name="error_loading_location">Error loading hashtag! Is the URL valid?</string>
<string name="error_creating_folders">Error creating Download folder(s).</string> <string name="error_creating_folders">Error creating Download folder(s).</string>
<string name="save_to_folder">Save to custom folder</string> <string name="save_to_folder">Save to custom folder</string>
<string name="select_folder">Select folder</string> <string name="select_folder">Select folder</string>

View File

@ -5,7 +5,7 @@ buildscript {
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:4.1.1' classpath 'com.android.tools.build:gradle:4.1.2'
def nav_version = "2.3.2" def nav_version = "2.3.2"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version" classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"
} }

View File

@ -1,7 +1,7 @@
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
distributionSha256Sum=0080de8491f0918e4f529a6db6820fa0b9e818ee2386117f4394f95feb1d5583 distributionSha256Sum=1433372d903ffba27496f8d5af24265310d2da0d78bf6b4e5138831d4fe066e9
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.2-all.zip
# https://gradle.org/releases/ # https://gradle.org/releases/
# https://gradle.org/release-checksums/ # https://gradle.org/release-checksums/
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME