|
@ -9,6 +9,7 @@ import android.graphics.drawable.ColorDrawable; |
|
|
import android.os.AsyncTask; |
|
|
import android.os.AsyncTask; |
|
|
import android.os.Bundle; |
|
|
import android.os.Bundle; |
|
|
import android.os.Environment; |
|
|
import android.os.Environment; |
|
|
|
|
|
import android.util.Log; |
|
|
import android.view.LayoutInflater; |
|
|
import android.view.LayoutInflater; |
|
|
import android.view.View; |
|
|
import android.view.View; |
|
|
import android.view.ViewGroup; |
|
|
import android.view.ViewGroup; |
|
@ -19,6 +20,7 @@ import androidx.annotation.NonNull; |
|
|
import androidx.annotation.Nullable; |
|
|
import androidx.annotation.Nullable; |
|
|
import androidx.core.content.ContextCompat; |
|
|
import androidx.core.content.ContextCompat; |
|
|
import androidx.fragment.app.DialogFragment; |
|
|
import androidx.fragment.app.DialogFragment; |
|
|
|
|
|
import androidx.fragment.app.FragmentActivity; |
|
|
|
|
|
|
|
|
import com.facebook.drawee.backends.pipeline.Fresco; |
|
|
import com.facebook.drawee.backends.pipeline.Fresco; |
|
|
import com.facebook.drawee.controller.BaseControllerListener; |
|
|
import com.facebook.drawee.controller.BaseControllerListener; |
|
@ -30,9 +32,20 @@ import java.io.File; |
|
|
import awais.instagrabber.R; |
|
|
import awais.instagrabber.R; |
|
|
import awais.instagrabber.asyncs.ProfilePictureFetcher; |
|
|
import awais.instagrabber.asyncs.ProfilePictureFetcher; |
|
|
import awais.instagrabber.databinding.DialogProfilepicBinding; |
|
|
import awais.instagrabber.databinding.DialogProfilepicBinding; |
|
|
|
|
|
import awais.instagrabber.db.entities.Account; |
|
|
|
|
|
import awais.instagrabber.db.repositories.RepositoryCallback; |
|
|
import awais.instagrabber.interfaces.FetchListener; |
|
|
import awais.instagrabber.interfaces.FetchListener; |
|
|
|
|
|
import awais.instagrabber.models.StoryModel; |
|
|
|
|
|
import awais.instagrabber.repositories.responses.UserInfo; |
|
|
|
|
|
import awais.instagrabber.utils.Constants; |
|
|
|
|
|
import awais.instagrabber.utils.CookieUtils; |
|
|
import awais.instagrabber.utils.DownloadUtils; |
|
|
import awais.instagrabber.utils.DownloadUtils; |
|
|
import awais.instagrabber.utils.TextUtils; |
|
|
import awais.instagrabber.utils.TextUtils; |
|
|
|
|
|
import awais.instagrabber.webservices.ProfileService; |
|
|
|
|
|
import awais.instagrabber.webservices.ServiceCallback; |
|
|
|
|
|
import awais.instagrabber.webservices.StoriesService; |
|
|
|
|
|
|
|
|
|
|
|
import static awais.instagrabber.utils.Utils.settingsHelper; |
|
|
|
|
|
|
|
|
public class ProfilePicDialogFragment extends DialogFragment { |
|
|
public class ProfilePicDialogFragment extends DialogFragment { |
|
|
private static final String TAG = "ProfilePicDlgFragment"; |
|
|
private static final String TAG = "ProfilePicDlgFragment"; |
|
@ -41,9 +54,15 @@ public class ProfilePicDialogFragment extends DialogFragment { |
|
|
private final String name; |
|
|
private final String name; |
|
|
private final String fallbackUrl; |
|
|
private final String fallbackUrl; |
|
|
|
|
|
|
|
|
|
|
|
private boolean isLoggedIn; |
|
|
private DialogProfilepicBinding binding; |
|
|
private DialogProfilepicBinding binding; |
|
|
private String url; |
|
|
private String url; |
|
|
|
|
|
|
|
|
|
|
|
private final FetchListener<String> fetchListener = profileUrl -> { |
|
|
|
|
|
url = profileUrl; |
|
|
|
|
|
setupPhoto(); |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
public ProfilePicDialogFragment(final String id, final String name, final String fallbackUrl) { |
|
|
public ProfilePicDialogFragment(final String id, final String name, final String fallbackUrl) { |
|
|
this.id = id; |
|
|
this.id = id; |
|
|
this.name = name; |
|
|
this.name = name; |
|
@ -55,6 +74,8 @@ public class ProfilePicDialogFragment extends DialogFragment { |
|
|
final ViewGroup container, |
|
|
final ViewGroup container, |
|
|
final Bundle savedInstanceState) { |
|
|
final Bundle savedInstanceState) { |
|
|
binding = DialogProfilepicBinding.inflate(inflater, container, false); |
|
|
binding = DialogProfilepicBinding.inflate(inflater, container, false); |
|
|
|
|
|
final String cookie = settingsHelper.getString(Constants.COOKIE); |
|
|
|
|
|
isLoggedIn = !TextUtils.isEmpty(cookie) && CookieUtils.getUserIdFromCookie(cookie) != null; |
|
|
return binding.getRoot(); |
|
|
return binding.getRoot(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -83,7 +104,8 @@ public class ProfilePicDialogFragment extends DialogFragment { |
|
|
public void onViewCreated(@NonNull final View view, @Nullable final Bundle savedInstanceState) { |
|
|
public void onViewCreated(@NonNull final View view, @Nullable final Bundle savedInstanceState) { |
|
|
super.onViewCreated(view, savedInstanceState); |
|
|
super.onViewCreated(view, savedInstanceState); |
|
|
init(); |
|
|
init(); |
|
|
fetchPhoto(); |
|
|
|
|
|
|
|
|
if (id.contains("_")) fetchStory(); |
|
|
|
|
|
else fetchAvatar(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private void init() { |
|
|
private void init() { |
|
@ -106,37 +128,75 @@ public class ProfilePicDialogFragment extends DialogFragment { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private void fetchPhoto() { |
|
|
|
|
|
final FetchListener<String> fetchListener = profileUrl -> { |
|
|
|
|
|
url = profileUrl; |
|
|
|
|
|
if (TextUtils.isEmpty(url)) { |
|
|
|
|
|
url = fallbackUrl; |
|
|
|
|
|
|
|
|
private void fetchAvatar() { |
|
|
|
|
|
if (isLoggedIn) { |
|
|
|
|
|
final ProfileService profileService = ProfileService.getInstance(); |
|
|
|
|
|
profileService.getUserInfo(id, new ServiceCallback<UserInfo>() { |
|
|
|
|
|
@Override |
|
|
|
|
|
public void onSuccess(final UserInfo result) { |
|
|
|
|
|
if (result != null) { |
|
|
|
|
|
fetchListener.onResult(result.getHDProfilePicUrl()); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public void onFailure(final Throwable t) { |
|
|
|
|
|
final Context context = getContext(); |
|
|
|
|
|
Toast.makeText(context, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show(); |
|
|
|
|
|
getDialog().dismiss(); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
else new ProfilePictureFetcher(name, id, fetchListener, fallbackUrl, false).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void fetchStory() { |
|
|
|
|
|
final StoriesService storiesService = StoriesService.getInstance(); |
|
|
|
|
|
storiesService.fetch(id, new ServiceCallback<StoryModel>() { |
|
|
|
|
|
@Override |
|
|
|
|
|
public void onSuccess(final StoryModel result) { |
|
|
|
|
|
if (result != null) { |
|
|
|
|
|
fetchListener.onResult(result.getStoryUrl()); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
final DraweeController controller = Fresco |
|
|
|
|
|
.newDraweeControllerBuilder() |
|
|
|
|
|
.setUri(url) |
|
|
|
|
|
.setOldController(binding.imageViewer.getController()) |
|
|
|
|
|
.setControllerListener(new BaseControllerListener<ImageInfo>() { |
|
|
|
|
|
@Override |
|
|
|
|
|
public void onFailure(final String id, final Throwable throwable) { |
|
|
|
|
|
super.onFailure(id, throwable); |
|
|
|
|
|
binding.download.setVisibility(View.GONE); |
|
|
|
|
|
binding.progressView.setVisibility(View.GONE); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public void onFinalImageSet(final String id, |
|
|
|
|
|
final ImageInfo imageInfo, |
|
|
|
|
|
final Animatable animatable) { |
|
|
|
|
|
super.onFinalImageSet(id, imageInfo, animatable); |
|
|
|
|
|
binding.download.setVisibility(View.VISIBLE); |
|
|
|
|
|
binding.progressView.setVisibility(View.GONE); |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
|
|
|
.build(); |
|
|
|
|
|
binding.imageViewer.setController(controller); |
|
|
|
|
|
}; |
|
|
|
|
|
new ProfilePictureFetcher(name, id, fetchListener, url, false).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public void onFailure(final Throwable t) { |
|
|
|
|
|
final Context context = getContext(); |
|
|
|
|
|
Log.d("austin_debug", "error", t); |
|
|
|
|
|
Toast.makeText(context, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show(); |
|
|
|
|
|
getDialog().dismiss(); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void setupPhoto() { |
|
|
|
|
|
if (TextUtils.isEmpty(url)) { |
|
|
|
|
|
url = fallbackUrl; |
|
|
|
|
|
} |
|
|
|
|
|
final DraweeController controller = Fresco |
|
|
|
|
|
.newDraweeControllerBuilder() |
|
|
|
|
|
.setUri(url) |
|
|
|
|
|
.setOldController(binding.imageViewer.getController()) |
|
|
|
|
|
.setControllerListener(new BaseControllerListener<ImageInfo>() { |
|
|
|
|
|
@Override |
|
|
|
|
|
public void onFailure(final String id, final Throwable throwable) { |
|
|
|
|
|
super.onFailure(id, throwable); |
|
|
|
|
|
binding.download.setVisibility(View.GONE); |
|
|
|
|
|
binding.progressView.setVisibility(View.GONE); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public void onFinalImageSet(final String id, |
|
|
|
|
|
final ImageInfo imageInfo, |
|
|
|
|
|
final Animatable animatable) { |
|
|
|
|
|
super.onFinalImageSet(id, imageInfo, animatable); |
|
|
|
|
|
binding.download.setVisibility(View.VISIBLE); |
|
|
|
|
|
binding.progressView.setVisibility(View.GONE); |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
|
|
|
.build(); |
|
|
|
|
|
binding.imageViewer.setController(controller); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private void downloadProfilePicture() { |
|
|
private void downloadProfilePicture() { |
|
|