mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-11-10 04:37:25 +01:00
Show a progress bar in ViewVideoActivity if it is a gfycat video and in ViewImgurMediaActivity.
This commit is contained in:
parent
13d64eda14
commit
470a59e104
@ -8,8 +8,8 @@ import android.os.Bundle;
|
|||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
import android.widget.ProgressBar;
|
import android.widget.ProgressBar;
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.appcompat.app.ActionBar;
|
import androidx.appcompat.app.ActionBar;
|
||||||
@ -61,6 +61,8 @@ public class ViewImgurMediaActivity extends AppCompatActivity {
|
|||||||
ProgressBar progressBar;
|
ProgressBar progressBar;
|
||||||
@BindView(R.id.view_pager_view_imgur_media_activity)
|
@BindView(R.id.view_pager_view_imgur_media_activity)
|
||||||
ViewPager viewPager;
|
ViewPager viewPager;
|
||||||
|
@BindView(R.id.load_image_error_linear_layout_view_imgur_media_activity)
|
||||||
|
LinearLayout errorLinearLayout;
|
||||||
private SectionsPagerAdapter sectionsPagerAdapter;
|
private SectionsPagerAdapter sectionsPagerAdapter;
|
||||||
private ArrayList<ImgurMedia> images;
|
private ArrayList<ImgurMedia> images;
|
||||||
@Inject
|
@Inject
|
||||||
@ -109,49 +111,60 @@ public class ViewImgurMediaActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (images == null) {
|
if (images == null) {
|
||||||
switch (getIntent().getIntExtra(EXTRA_IMGUR_TYPE, IMGUR_TYPE_IMAGE)) {
|
fetchImgurMedia(imgurId);
|
||||||
case IMGUR_TYPE_GALLERY:
|
|
||||||
imgurRetrofit.create(ImgurAPI.class).getGalleryImages(APIUtils.IMGUR_CLIENT_ID, imgurId)
|
|
||||||
.enqueue(new Callback<String>() {
|
|
||||||
@Override
|
|
||||||
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
|
|
||||||
if (response.isSuccessful()) {
|
|
||||||
new ParseImgurImagesAsyncTask(response.body(), new ParseImgurImagesAsyncTask.ParseImgurImagesAsyncTaskListener() {
|
|
||||||
@Override
|
|
||||||
public void success(ArrayList<ImgurMedia> images) {
|
|
||||||
ViewImgurMediaActivity.this.images = images;
|
|
||||||
progressBar.setVisibility(View.GONE);
|
|
||||||
setupViewPager();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void failed() {
|
|
||||||
progressBar.setVisibility(View.GONE);
|
|
||||||
Toast.makeText(ViewImgurMediaActivity.this, R.string.error_fetching_imgur_media, Toast.LENGTH_SHORT).show();
|
|
||||||
}
|
|
||||||
}).execute();
|
|
||||||
} else {
|
|
||||||
progressBar.setVisibility(View.GONE);
|
|
||||||
Toast.makeText(ViewImgurMediaActivity.this, R.string.error_fetching_imgur_media, Toast.LENGTH_SHORT).show();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
|
|
||||||
progressBar.setVisibility(View.GONE);
|
|
||||||
Toast.makeText(ViewImgurMediaActivity.this, R.string.error_fetching_imgur_media, Toast.LENGTH_SHORT).show();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
break;
|
|
||||||
case IMGUR_TYPE_ALBUM:
|
|
||||||
break;
|
|
||||||
case IMGUR_TYPE_IMAGE:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
progressBar.setVisibility(View.GONE);
|
progressBar.setVisibility(View.GONE);
|
||||||
setupViewPager();
|
setupViewPager();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
errorLinearLayout.setOnClickListener(view -> {
|
||||||
|
fetchImgurMedia(imgurId);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void fetchImgurMedia(String imgurId) {
|
||||||
|
errorLinearLayout.setVisibility(View.GONE);
|
||||||
|
progressBar.setVisibility(View.VISIBLE);
|
||||||
|
switch (getIntent().getIntExtra(EXTRA_IMGUR_TYPE, IMGUR_TYPE_IMAGE)) {
|
||||||
|
case IMGUR_TYPE_GALLERY:
|
||||||
|
imgurRetrofit.create(ImgurAPI.class).getGalleryImages(APIUtils.IMGUR_CLIENT_ID, imgurId)
|
||||||
|
.enqueue(new Callback<String>() {
|
||||||
|
@Override
|
||||||
|
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
|
||||||
|
if (response.isSuccessful()) {
|
||||||
|
new ParseImgurImagesAsyncTask(response.body(), new ParseImgurImagesAsyncTask.ParseImgurImagesAsyncTaskListener() {
|
||||||
|
@Override
|
||||||
|
public void success(ArrayList<ImgurMedia> images) {
|
||||||
|
ViewImgurMediaActivity.this.images = images;
|
||||||
|
progressBar.setVisibility(View.GONE);
|
||||||
|
errorLinearLayout.setVisibility(View.GONE);
|
||||||
|
setupViewPager();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void failed() {
|
||||||
|
progressBar.setVisibility(View.GONE);
|
||||||
|
errorLinearLayout.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
}).execute();
|
||||||
|
} else {
|
||||||
|
progressBar.setVisibility(View.GONE);
|
||||||
|
errorLinearLayout.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
|
||||||
|
progressBar.setVisibility(View.GONE);
|
||||||
|
errorLinearLayout.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case IMGUR_TYPE_ALBUM:
|
||||||
|
break;
|
||||||
|
case IMGUR_TYPE_IMAGE:
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupViewPager() {
|
private void setupViewPager() {
|
||||||
|
@ -26,6 +26,7 @@ import android.view.View;
|
|||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.ProgressBar;
|
||||||
import android.widget.RelativeLayout;
|
import android.widget.RelativeLayout;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
@ -85,6 +86,8 @@ public class ViewVideoActivity extends AppCompatActivity {
|
|||||||
private static final String VIDEO_URI_STATE = "VUS";
|
private static final String VIDEO_URI_STATE = "VUS";
|
||||||
@BindView(R.id.relative_layout_view_video_activity)
|
@BindView(R.id.relative_layout_view_video_activity)
|
||||||
RelativeLayout relativeLayout;
|
RelativeLayout relativeLayout;
|
||||||
|
@BindView(R.id.progress_bar_view_video_activity)
|
||||||
|
ProgressBar progressBar;
|
||||||
@BindView(R.id.player_view_view_video_activity)
|
@BindView(R.id.player_view_view_video_activity)
|
||||||
PlayerView videoPlayerView;
|
PlayerView videoPlayerView;
|
||||||
@BindView(R.id.mute_exo_playback_control_view)
|
@BindView(R.id.mute_exo_playback_control_view)
|
||||||
@ -342,6 +345,7 @@ public class ViewVideoActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (mVideoUri == null) {
|
if (mVideoUri == null) {
|
||||||
|
progressBar.setVisibility(View.VISIBLE);
|
||||||
String gfycatId = intent.getStringExtra(EXTRA_GFYCAT_ID);
|
String gfycatId = intent.getStringExtra(EXTRA_GFYCAT_ID);
|
||||||
if (gfycatId != null && gfycatId.contains("-")) {
|
if (gfycatId != null && gfycatId.contains("-")) {
|
||||||
gfycatId = gfycatId.substring(0, gfycatId.indexOf('-'));
|
gfycatId = gfycatId.substring(0, gfycatId.indexOf('-'));
|
||||||
@ -351,6 +355,7 @@ public class ViewVideoActivity extends AppCompatActivity {
|
|||||||
new FetchGfycatVideoLinks.FetchGfycatVideoLinksListener() {
|
new FetchGfycatVideoLinks.FetchGfycatVideoLinksListener() {
|
||||||
@Override
|
@Override
|
||||||
public void success(String webm, String mp4) {
|
public void success(String webm, String mp4) {
|
||||||
|
progressBar.setVisibility(View.GONE);
|
||||||
mVideoUri = Uri.parse(webm);
|
mVideoUri = Uri.parse(webm);
|
||||||
videoDownloadUrl = mp4;
|
videoDownloadUrl = mp4;
|
||||||
dataSourceFactory = new DefaultDataSourceFactory(ViewVideoActivity.this,
|
dataSourceFactory = new DefaultDataSourceFactory(ViewVideoActivity.this,
|
||||||
@ -361,6 +366,7 @@ public class ViewVideoActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void failed() {
|
public void failed() {
|
||||||
|
progressBar.setVisibility(View.GONE);
|
||||||
Toast.makeText(ViewVideoActivity.this, R.string.fetch_gfycat_video_failed, Toast.LENGTH_SHORT).show();
|
Toast.makeText(ViewVideoActivity.this, R.string.fetch_gfycat_video_failed, Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -16,4 +16,22 @@
|
|||||||
android:id="@+id/view_pager_view_imgur_media_activity"
|
android:id="@+id/view_pager_view_imgur_media_activity"
|
||||||
tools:context=".Activity.ViewImgurMediaActivity" />
|
tools:context=".Activity.ViewImgurMediaActivity" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/load_image_error_linear_layout_view_imgur_media_activity"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:visibility="gone">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:drawableTop="@drawable/ic_error_outline_white_24dp"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:gravity="center"
|
||||||
|
android:textColor="@android:color/white"
|
||||||
|
android:text="@string/error_loading_image_tap_to_retry"
|
||||||
|
android:textSize="?attr/font_default" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
@ -15,4 +15,11 @@
|
|||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
app:controller_layout_id="@layout/exo_playback_control_view"/>
|
app:controller_layout_id="@layout/exo_playback_control_view"/>
|
||||||
|
|
||||||
|
<ProgressBar
|
||||||
|
android:id="@+id/progress_bar_view_video_activity"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_centerInParent="true"
|
||||||
|
android:visibility="gone" />
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
Loading…
Reference in New Issue
Block a user