From b2e784deb81b78fd49699c38852bd5e03a038097 Mon Sep 17 00:00:00 2001 From: Austin Huang Date: Mon, 30 Nov 2020 12:29:41 -0500 Subject: [PATCH] close #306 and close #310 --- .../instagrabber/activities/MainActivity.java | 16 +++++++++++----- .../instagrabber/asyncs/ProfileFetcher.java | 12 ++++++++---- .../fragments/main/ProfileFragment.java | 2 ++ app/src/main/res/drawable/lock.xml | 3 +-- app/src/main/res/layout/fragment_profile.xml | 4 ++-- app/src/main/res/values/strings.xml | 1 + 6 files changed, 25 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/activities/MainActivity.java b/app/src/main/java/awais/instagrabber/activities/MainActivity.java index 4643a3a8..3986e4f4 100644 --- a/app/src/main/java/awais/instagrabber/activities/MainActivity.java +++ b/app/src/main/java/awais/instagrabber/activities/MainActivity.java @@ -21,6 +21,7 @@ import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.AutoCompleteTextView; +import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -546,11 +547,16 @@ public class MainActivity extends BaseLanguageActivity implements FragmentManage .create(); alertDialog.show(); new PostFetcher(shortCode, feedModel -> { - final PostViewV2Fragment fragment = PostViewV2Fragment - .builder(feedModel) - .build(); - fragment.setOnShowListener(dialog -> alertDialog.dismiss()); - fragment.show(getSupportFragmentManager(), "post_view"); + if (feedModel != null) { + final PostViewV2Fragment fragment = PostViewV2Fragment + .builder(feedModel) + .build(); + fragment.setOnShowListener(dialog -> alertDialog.dismiss()); + fragment.show(getSupportFragmentManager(), "post_view"); + } + else { + Toast.makeText(getApplicationContext(), R.string.post_not_found, Toast.LENGTH_SHORT).show(); + } }).execute(); } diff --git a/app/src/main/java/awais/instagrabber/asyncs/ProfileFetcher.java b/app/src/main/java/awais/instagrabber/asyncs/ProfileFetcher.java index 678d2d0c..e2e4fe2c 100755 --- a/app/src/main/java/awais/instagrabber/asyncs/ProfileFetcher.java +++ b/app/src/main/java/awais/instagrabber/asyncs/ProfileFetcher.java @@ -15,11 +15,13 @@ import awais.instagrabber.BuildConfig; import awais.instagrabber.interfaces.FetchListener; import awais.instagrabber.models.ProfileModel; import awais.instagrabber.utils.Constants; +import awais.instagrabber.utils.CookieUtils; import awais.instagrabber.utils.NetworkUtils; import awais.instagrabber.utils.TextUtils; import awaisomereport.LogCollector; import static awais.instagrabber.utils.Utils.logCollector; +import static awais.instagrabber.utils.Utils.settingsHelper; public final class ProfileFetcher extends AsyncTask { private final FetchListener fetchListener; @@ -43,21 +45,23 @@ public final class ProfileFetcher extends AsyncTask { if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) { final JSONObject user = new JSONObject(NetworkUtils.readFromConnection(conn)).getJSONObject("graphql").getJSONObject(Constants.EXTRAS_USER); + final String cookie = settingsHelper.getString(Constants.COOKIE); + boolean isPrivate = user.getBoolean("is_private"); - boolean reallyPrivate = isPrivate; + final String id = user.getString(Constants.EXTRAS_ID); + final String uid = CookieUtils.getUserIdFromCookie(cookie); final JSONObject timelineMedia = user.getJSONObject("edge_owner_to_timeline_media"); if (timelineMedia.has("edges")) { final JSONArray edges = timelineMedia.getJSONArray("edges"); - if (edges.length() > 0 && timelineMedia.getLong("count") > 0L) reallyPrivate = false; } String url = user.optString("external_url"); if (TextUtils.isEmpty(url)) url = null; result = new ProfileModel(isPrivate, - reallyPrivate, + user.optBoolean("followed_by_viewer") ? false : (id.equals(uid) ? false : isPrivate), user.getBoolean("is_verified"), - user.getString(Constants.EXTRAS_ID), + id, userName, user.getString("full_name"), user.getString("biography"), diff --git a/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java b/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java index 829941ab..022e056e 100644 --- a/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java @@ -13,6 +13,7 @@ import android.text.style.RelativeSizeSpan; import android.text.style.StyleSpan; import android.util.Log; import android.view.ActionMode; +import android.view.Gravity; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; @@ -477,6 +478,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe binding.privatePage2.setText(R.string.no_acc); final CoordinatorLayout.LayoutParams layoutParams = (CoordinatorLayout.LayoutParams) binding.privatePage.getLayoutParams(); layoutParams.topMargin = 0; + layoutParams.gravity = Gravity.CENTER; binding.privatePage.setLayoutParams(layoutParams); binding.privatePage.setVisibility(View.VISIBLE); return; diff --git a/app/src/main/res/drawable/lock.xml b/app/src/main/res/drawable/lock.xml index 4bb23a77..aa15a437 100755 --- a/app/src/main/res/drawable/lock.xml +++ b/app/src/main/res/drawable/lock.xml @@ -1,12 +1,11 @@ diff --git a/app/src/main/res/layout/fragment_profile.xml b/app/src/main/res/layout/fragment_profile.xml index 5bf6a013..a1baa934 100644 --- a/app/src/main/res/layout/fragment_profile.xml +++ b/app/src/main/res/layout/fragment_profile.xml @@ -41,12 +41,12 @@ android:id="@+id/privatePage" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_gravity="center" + android:layout_gravity="top" android:layout_marginTop="@dimen/private_page_margins" android:gravity="center" android:orientation="vertical" android:visibility="gone" - tools:visibility="gone"> + tools:visibility="visible"> Show grid gap Disable animation Please wait for the current task to complete first! + Post not found! %d like %d likes