Skip to content

Commit

Permalink
progress bar update
Browse files Browse the repository at this point in the history
  • Loading branch information
yuliskov committed Oct 25, 2020
1 parent 5b77025 commit ab887c1
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand Down Expand Up @@ -55,6 +56,7 @@ public void onCreate(Bundle savedInstanceState) {
mBrowsePresenter.register(this);
mCreateAlreadyCalled = true;
mProgressBarManager = new ProgressBarManager();
//mProgressBarManager.setPosition(Gravity.BOTTOM | Gravity.CENTER);

setupAdapter();
setupUi();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package com.liskovsoft.smartyoutubetv2.tv.ui.mod.leanback;

import android.content.Context;
import android.os.Handler;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ProgressBar;
import androidx.core.content.ContextCompat;
import androidx.leanback.app.BrowseFragment;
import androidx.leanback.app.VerticalGridFragment;
import com.liskovsoft.sharedutils.helpers.Helpers;
import com.liskovsoft.smartyoutubetv2.tv.R;

/**
* Manager for showing/hiding progress bar widget. This class lets user specify an initial
Expand All @@ -26,6 +30,7 @@ public final class ProgressBarManager {
boolean mEnableProgressBar = true;
boolean mUserProvidedProgressBar;
boolean mIsShowing;
private int mPosition = Gravity.CENTER;

private Runnable runnable = new Runnable() {
@Override
Expand All @@ -36,20 +41,30 @@ public void run() {

if (mIsShowing) {
if (mProgressBarView == null) {
mProgressBarView = new ProgressBar(
rootView.getContext(), null, android.R.attr.progressBarStyleLarge);
FrameLayout.LayoutParams progressBarParams = new FrameLayout.LayoutParams(
FrameLayout.LayoutParams.WRAP_CONTENT,
FrameLayout.LayoutParams.WRAP_CONTENT);
progressBarParams.gravity = Gravity.BOTTOM | Gravity.CENTER; // MOD: custom align
rootView.addView(mProgressBarView, progressBarParams);
mProgressBarView = createProgressBar(rootView, mPosition);
} else if (mUserProvidedProgressBar) {
mProgressBarView.setVisibility(View.VISIBLE);
}
}
}
};

private static View createProgressBar(ViewGroup rootView, int position) {
ProgressBar progressBarView = new ProgressBar(
rootView.getContext(), null, android.R.attr.progressBarStyleLarge);
progressBarView.setIndeterminate(true);
progressBarView.setIndeterminateDrawable(
ContextCompat.getDrawable(rootView.getContext(), R.drawable.progress_large_holo));

FrameLayout.LayoutParams progressBarParams = new FrameLayout.LayoutParams(
FrameLayout.LayoutParams.WRAP_CONTENT,
FrameLayout.LayoutParams.WRAP_CONTENT);
progressBarParams.gravity = position;
rootView.addView(progressBarView, progressBarParams);

return progressBarView;
}

/**
* Sets the root view on which the progress bar will be attached. This class assumes the
* root view to be {@link FrameLayout} in order to position the progress bar widget
Expand Down Expand Up @@ -131,4 +146,16 @@ public void disableProgressBar() {
public void enableProgressBar() {
mEnableProgressBar = true;
}

public void setPosition(int position) {
mPosition = position;
}

public static void setup(androidx.leanback.app.ProgressBarManager manager) {
ViewGroup rootView = (ViewGroup) Helpers.getField(manager, "rootView");

if (rootView != null) {
manager.setProgressBarView(createProgressBar(rootView, Gravity.CENTER));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ProgressBar;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.leanback.app.RowsSupportFragment;
Expand Down Expand Up @@ -47,6 +50,7 @@
import com.liskovsoft.smartyoutubetv2.tv.adapter.VideoGroupObjectAdapter;
import com.liskovsoft.smartyoutubetv2.tv.ui.common.LeanbackActivity;
import com.liskovsoft.smartyoutubetv2.tv.ui.common.UriBackgroundManager;
import com.liskovsoft.smartyoutubetv2.tv.ui.mod.leanback.ProgressBarManager;

import java.io.InputStream;
import java.util.HashMap;
Expand Down Expand Up @@ -102,6 +106,16 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) {
mPlaybackPresenter.onInitDone();
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = super.onCreateView(inflater, container, savedInstanceState);

// ProgressBar.setRootView is called in this moment
ProgressBarManager.setup(getProgressBarManager());

return view;
}

private void setupPlayerBackground() {
// Make player controls more distinguished on white background
//setBackgroundType(BG_NONE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand Down Expand Up @@ -62,6 +63,7 @@ public void onCreate(Bundle savedInstanceState) {

mRowsAdapter = new ArrayObjectAdapter(new ListRowPresenter());
mProgressBarManager = new ProgressBarManager();
//mProgressBarManager.setPosition(Gravity.BOTTOM | Gravity.CENTER);

setSearchResultProvider(this);
setupEventListeners();
Expand Down

0 comments on commit ab887c1

Please sign in to comment.