Browse Source

Merge remote-tracking branch 'origin/dm-notifications-enhancements' into dm-notifications-enhancements

renovate/org.robolectric-robolectric-4.x
Ammar Githam 4 years ago
parent
commit
ff296c3bfc
  1. 3
      app/build.gradle
  2. 9
      app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemViewHolder.java
  3. 93
      app/src/main/java/awais/instagrabber/asyncs/ProfilePictureFetcher.java
  4. 20
      app/src/main/java/awais/instagrabber/dialogs/ProfilePicDialogFragment.java
  5. 7
      app/src/main/java/awais/instagrabber/fragments/FavoritesFragment.java
  6. 17
      app/src/main/java/awais/instagrabber/fragments/settings/AboutFragment.java
  7. 23
      app/src/main/java/awais/instagrabber/fragments/settings/SettingsPreferencesFragment.java
  8. 2
      app/src/main/java/awais/instagrabber/utils/Constants.java
  9. 3
      app/src/main/java/awais/instagrabber/utils/SettingsHelper.java
  10. 34
      app/src/main/res/values/arrays.xml

3
app/build.gradle

@ -92,16 +92,13 @@ dependencies {
implementation "androidx.camera:camera-lifecycle:$camerax_version"
implementation "androidx.camera:camera-view:1.0.0-alpha20"
// EmojiCompat
def emoji_compat_version = "1.1.0"
implementation "androidx.emoji:emoji:$emoji_compat_version"
implementation "androidx.emoji:emoji-appcompat:$emoji_compat_version"
// implementation 'com.github.hendrawd:StorageUtil:1.1.0'
implementation 'me.austinhuang:AutoLinkTextViewV2:-SNAPSHOT'
implementation 'org.jsoup:jsoup:1.13.1'
implementation 'com.facebook.fresco:fresco:2.3.0'
implementation 'com.facebook.fresco:animated-webp:2.3.0'
implementation 'com.facebook.fresco:webpsupport:2.3.0'

9
app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemViewHolder.java

@ -4,6 +4,7 @@ import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.text.format.DateFormat;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.View;
import android.widget.FrameLayout;
@ -42,6 +43,7 @@ public abstract class DirectItemViewHolder extends RecyclerView.ViewHolder {
private final int dmRadius;
private final int messageInfoPaddingSmall;
private final int dmRadiusSmall;
private final int groupMessageWidth;
private final List<Long> userIds;
public DirectItemViewHolder(@NonNull final LayoutDmBaseBinding binding,
@ -60,10 +62,14 @@ public abstract class DirectItemViewHolder extends RecyclerView.ViewHolder {
binding.ivProfilePic.setOnClickListener(thread.isGroup() ? onClickListener : null);
// binding.messageCard.setOnClickListener(onClickListener);
margin = itemView.getResources().getDimensionPixelSize(R.dimen.dm_message_item_margin);
final int avatarSize = Utils.convertDpToPx(48);
final Resources resources = itemView.getResources();
dmRadius = resources.getDimensionPixelSize(R.dimen.dm_message_card_radius);
dmRadiusSmall = resources.getDimensionPixelSize(R.dimen.dm_message_card_radius_small);
messageInfoPaddingSmall = Utils.convertDpToPx(4);
DisplayMetrics displayMetrics = itemView.getResources().getDisplayMetrics();
// messageInfoPaddingSmall is used cuz it's also 4dp, 1 avatar margin + 2 paddings = 3
groupMessageWidth = displayMetrics.widthPixels - margin - avatarSize - messageInfoPaddingSmall * 3;
}
public void bind(final DirectItem item) {
@ -86,6 +92,9 @@ public abstract class DirectItemViewHolder extends RecyclerView.ViewHolder {
binding.tvUsername.setText(user.getUsername());
binding.ivProfilePic.setImageURI(user.getProfilePicUrl());
}
ConstraintLayout.LayoutParams layoutParams = (ConstraintLayout.LayoutParams) binding.chatMessageLayout.getLayoutParams();
layoutParams.matchConstraintMaxWidth = groupMessageWidth;
binding.chatMessageLayout.setLayoutParams(layoutParams);
}
} else {
binding.ivProfilePic.setVisibility(View.GONE);

93
app/src/main/java/awais/instagrabber/asyncs/ProfilePictureFetcher.java

@ -1,93 +0,0 @@
package awais.instagrabber.asyncs;
import android.os.AsyncTask;
import android.util.Log;
import org.json.JSONObject;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import java.net.HttpURLConnection;
import java.net.URL;
import awais.instagrabber.BuildConfig;
import awais.instagrabber.interfaces.FetchListener;
import awais.instagrabber.utils.Constants;
import awais.instagrabber.utils.NetworkUtils;
import awais.instagrabber.utils.TextUtils;
import awais.instagrabber.utils.Utils;
import awaisomereport.LogCollector;
import static awais.instagrabber.utils.Utils.logCollector;
public final class ProfilePictureFetcher extends AsyncTask<Void, Void, String> {
private final FetchListener<String> fetchListener;
private final String userName, userId, picUrl;
private final boolean isHashtag;
public ProfilePictureFetcher(final String userName, final String userId, final FetchListener<String> fetchListener,
final String picUrl, final boolean isHashtag) {
this.fetchListener = fetchListener;
this.userName = userName;
this.userId = userId;
this.picUrl = picUrl;
this.isHashtag = isHashtag;
}
@Override
protected String doInBackground(final Void... voids) {
String out = null;
if (isHashtag) out = picUrl;
else if (Utils.settingsHelper.getBoolean(Constants.INSTADP)) try {
final HttpURLConnection backup =
(HttpURLConnection) new URL("https://instadp.com/fullsize/" + userName).openConnection();
backup.setUseCaches(false);
backup.setRequestMethod("GET");
backup.setRequestProperty("User-Agent", Constants.A_USER_AGENT);
final String instadp = backup.getResponseCode() == HttpURLConnection.HTTP_OK ? NetworkUtils.readFromConnection(backup) : null;
backup.disconnect();
if (!TextUtils.isEmpty(instadp)) {
final Document doc = Jsoup.parse(instadp);
boolean fallback = false;
final int imgIndex = instadp.indexOf("preloadImg('"), lastIndex;
Element element = doc.selectFirst(".instadp");
if (element != null && (element = element.selectFirst(".picture")) != null)
out = element.attr("src");
else if ((element = doc.selectFirst(".download-btn")) != null)
out = element.attr("href");
else if (imgIndex != -1 && (lastIndex = instadp.indexOf("')", imgIndex)) != -1)
out = instadp.substring(imgIndex + 12, lastIndex);
else {
final Elements imgs = doc.getElementsByTag("img");
for (final Element img : imgs) {
final String imgStr = img.toString();
if (imgStr.contains("cdninstagram.com")) out = img.attr("src");
}
}
}
if (TextUtils.isEmpty(out)) out = picUrl;
} catch (final Exception e) {
if (logCollector != null)
logCollector.appendException(e, LogCollector.LogFile.ASYNC_PROFILE_PICTURE_FETCHER, "doInBackground");
if (BuildConfig.DEBUG) Log.e("AWAISKING_APP", "", e);
}
return out;
}
@Override
protected void onPreExecute() {
if (fetchListener != null) fetchListener.doBefore();
}
@Override
protected void onPostExecute(final String result) {
if (fetchListener != null) fetchListener.onResult(result);
}
}

20
app/src/main/java/awais/instagrabber/dialogs/ProfilePicDialogFragment.java

@ -6,7 +6,6 @@ import android.content.pm.PackageManager;
import android.graphics.Color;
import android.graphics.drawable.Animatable;
import android.graphics.drawable.ColorDrawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.view.LayoutInflater;
@ -28,9 +27,7 @@ import com.facebook.imagepipeline.image.ImageInfo;
import java.io.File;
import awais.instagrabber.R;
import awais.instagrabber.asyncs.ProfilePictureFetcher;
import awais.instagrabber.databinding.DialogProfilepicBinding;
import awais.instagrabber.interfaces.FetchListener;
import awais.instagrabber.repositories.responses.UserInfo;
import awais.instagrabber.utils.Constants;
import awais.instagrabber.utils.CookieUtils;
@ -52,11 +49,6 @@ public class ProfilePicDialogFragment extends DialogFragment {
private DialogProfilepicBinding binding;
private String url;
private final FetchListener<String> fetchListener = profileUrl -> {
url = profileUrl;
setupPhoto();
};
public ProfilePicDialogFragment(final String id, final String name, final String fallbackUrl) {
this.id = id;
this.name = name;
@ -128,7 +120,7 @@ public class ProfilePicDialogFragment extends DialogFragment {
@Override
public void onSuccess(final UserInfo result) {
if (result != null) {
fetchListener.onResult(result.getHDProfilePicUrl());
setupPhoto(result.getHDProfilePicUrl());
}
}
@ -139,15 +131,13 @@ public class ProfilePicDialogFragment extends DialogFragment {
getDialog().dismiss();
}
});
return;
}
new ProfilePictureFetcher(name, id, fetchListener, fallbackUrl, false).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
else setupPhoto(fallbackUrl);
}
private void setupPhoto() {
if (TextUtils.isEmpty(url)) {
url = fallbackUrl;
}
private void setupPhoto(final String result) {
if (TextUtils.isEmpty(result)) url = fallbackUrl;
else url = result;
final DraweeController controller = Fresco
.newDraweeControllerBuilder()
.setUri(url)

7
app/src/main/java/awais/instagrabber/fragments/FavoritesFragment.java

@ -2,7 +2,6 @@ package awais.instagrabber.fragments;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -18,21 +17,15 @@ import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;
import awais.instagrabber.R;
import awais.instagrabber.adapters.FavoritesAdapter;
import awais.instagrabber.asyncs.LocationFetcher;
import awais.instagrabber.asyncs.ProfileFetcher;
import awais.instagrabber.databinding.FragmentFavoritesBinding;
import awais.instagrabber.db.datasources.FavoriteDataSource;
import awais.instagrabber.db.entities.Favorite;
import awais.instagrabber.db.repositories.FavoriteRepository;
import awais.instagrabber.db.repositories.RepositoryCallback;
import awais.instagrabber.utils.TextUtils;
import awais.instagrabber.viewmodels.FavoritesViewModel;
public class FavoritesFragment extends Fragment {

17
app/src/main/java/awais/instagrabber/fragments/settings/AboutFragment.java

@ -43,7 +43,6 @@ public class AboutFragment extends BasePreferencesFragment {
thirdPartyCategory.addPreference(getAutolinkPreference());
thirdPartyCategory.addPreference(getExoPlayerPreference());
thirdPartyCategory.addPreference(getFrescoPreference());
thirdPartyCategory.addPreference(getJsoupPreference());
thirdPartyCategory.addPreference(getMDIPreference());
thirdPartyCategory.addPreference(getRetrofitPreference());
}
@ -114,22 +113,6 @@ public class AboutFragment extends BasePreferencesFragment {
return preference;
}
private Preference getJsoupPreference() {
final Context context = getContext();
if (context == null) return null;
final Preference preference = new Preference(context);
preference.setTitle("jsoup");
preference.setSummary("Copyright (c) 2009-2020 Jonathan Hedley. MIT License.");
preference.setIconSpaceReserved(false);
preference.setOnPreferenceClickListener(p -> {
final Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("https://jsoup.org/"));
startActivity(intent);
return true;
});
return preference;
}
private Preference getFrescoPreference() {
final Context context = getContext();
if (context == null) return null;

23
app/src/main/java/awais/instagrabber/fragments/settings/SettingsPreferencesFragment.java

@ -83,14 +83,13 @@ public class SettingsPreferencesFragment extends BasePreferencesFragment {
loggedInUsersPreferenceCategory.addPreference(getMarkStoriesSeenPreference());
loggedInUsersPreferenceCategory.addPreference(getMarkDMSeenPreference());
loggedInUsersPreferenceCategory.addPreference(getEnableActivityNotificationsPreference());
} else {
final PreferenceCategory anonUsersPreferenceCategory = new PreferenceCategory(context);
screen.addPreference(anonUsersPreferenceCategory);
anonUsersPreferenceCategory.setIconSpaceReserved(false);
anonUsersPreferenceCategory.setTitle(R.string.anonymous_settings);
anonUsersPreferenceCategory.addPreference(getUseInstaDpPreference());
}
// else {
// final PreferenceCategory anonUsersPreferenceCategory = new PreferenceCategory(context);
// screen.addPreference(anonUsersPreferenceCategory);
// anonUsersPreferenceCategory.setIconSpaceReserved(false);
// anonUsersPreferenceCategory.setTitle(R.string.anonymous_settings);
// }
}
private Preference getLanguagePreference() {
@ -260,16 +259,6 @@ public class SettingsPreferencesFragment extends BasePreferencesFragment {
return preference;
}
private Preference getUseInstaDpPreference() {
final Context context = getContext();
if (context == null) return null;
final SwitchPreferenceCompat preference = new SwitchPreferenceCompat(context);
preference.setKey(Constants.INSTADP);
preference.setTitle(R.string.instadp_settings);
preference.setIconSpaceReserved(false);
return preference;
}
private Preference getPostTimePreference() {
final Context context = getContext();
if (context == null) return null;

2
app/src/main/java/awais/instagrabber/utils/Constants.java

@ -21,7 +21,7 @@ public final class Constants {
public static final String SWAP_DATE_TIME_FORMAT_ENABLED = "swap_date_time_enabled";
public static final String MARK_AS_SEEN = "mark_as_seen";
public static final String DM_MARK_AS_SEEN = "dm_mark_as_seen";
public static final String INSTADP = "instadp";
// deprecated: public static final String INSTADP = "instadp";
// deprecated: public static final String STORIESIG = "storiesig";
// deprecated: public static final String STORY_VIEWER = "story_viewer";
// deprecated: public static final String AMOLED_THEME = "amoled_theme";

3
app/src/main/java/awais/instagrabber/utils/SettingsHelper.java

@ -24,7 +24,6 @@ import static awais.instagrabber.utils.Constants.DM_MARK_AS_SEEN;
import static awais.instagrabber.utils.Constants.DOWNLOAD_USER_FOLDER;
import static awais.instagrabber.utils.Constants.FOLDER_PATH;
import static awais.instagrabber.utils.Constants.FOLDER_SAVE_TO;
import static awais.instagrabber.utils.Constants.INSTADP;
import static awais.instagrabber.utils.Constants.MARK_AS_SEEN;
import static awais.instagrabber.utils.Constants.MUTED_VIDEOS;
import static awais.instagrabber.utils.Constants.PREF_DARK_THEME;
@ -128,7 +127,7 @@ public final class SettingsHelper {
public @interface StringSettings {}
@StringDef({DOWNLOAD_USER_FOLDER, FOLDER_SAVE_TO, AUTOPLAY_VIDEOS, SHOW_QUICK_ACCESS_DIALOG, MUTED_VIDEOS,
CUSTOM_DATE_TIME_FORMAT_ENABLED, MARK_AS_SEEN, DM_MARK_AS_SEEN, INSTADP, CHECK_ACTIVITY,
CUSTOM_DATE_TIME_FORMAT_ENABLED, MARK_AS_SEEN, DM_MARK_AS_SEEN, CHECK_ACTIVITY,
CHECK_UPDATES, SWAP_DATE_TIME_FORMAT_ENABLED})
public @interface BooleanSettings {}

34
app/src/main/res/values/arrays.xml

@ -3,25 +3,25 @@
<string-array name="languages">
<item>System Default</item>
<item translatable="false">English</item>
<item translatable="false">Français [Merci à @kernoeb et @PierreM0]</item>
<item translatable="false">Español [Gracias a @sguinetti, @akrai y @retiolus]</item>
<item translatable="false">Français</item>
<item translatable="false">Español</item>
<item translatable="false">简体中文</item>
<item translatable="false">Bahasa Indonesia [Terima kasih @Galang23]</item>
<item translatable="false">Italiano [Grazie a @RAR_Ramar e GiorgioHerbie]</item>
<item translatable="false">Deutsch [Danke an @peterge1998]</item>
<item translatable="false">Polski [Podziękowania dla @Lego8486]</item>
<item translatable="false">Türkçe [@faydin90 tarafından]</item>
<item translatable="false">Português (Brasil) [Obrigado @wagnim, @RickyM7 e @cizordj]</item>
<item translatable="false">پارسی [ با سپاس از farzadx@ ]</item>
<item translatable="false">Македонски [Благодарност до @snajdovski]</item>
<item translatable="false">Tiếng Việt [bởi Yato Fouze]</item>
<item translatable="false">繁體中文 [感謝 @Still34]</item>
<item translatable="false">Català [Gràcies a @retiolus]</item>
<item translatable="false">Русский [Спасибо @rikishi0071]</item>
<item translatable="false">Bahasa Indonesia</item>
<item translatable="false">Italiano</item>
<item translatable="false">Deutsch</item>
<item translatable="false">Polski</item>
<item translatable="false">Türkçe</item>
<item translatable="false">Português (Brasil)</item>
<item translatable="false">پارسی</item>
<item translatable="false">Македонски</item>
<item translatable="false">Tiếng Việt</item>
<item translatable="false">繁體中文</item>
<item translatable="false">Català</item>
<item translatable="false">Русский</item>
<item translatable="false">हिन्दी</item>
<item translatable="false">Nederlands [Met dank aan Lesley Natrop]</item>
<item translatable="false">Slovenčina [Vďaka @CrafterSvK]</item>
<item translatable="false">日本語 [協力 ysakamoto]</item>
<item translatable="false">Nederlands</item>
<item translatable="false">Slovenčina</item>
<item translatable="false">日本語</item>
</string-array>
<string-array name="theme_presets">
<item>Auto / Follow System</item>

Loading…
Cancel
Save