Display content only when available
This commit is contained in:
parent
3f35f75020
commit
03914d7e71
|
@ -20,7 +20,8 @@ import android.webkit.WebView;
|
|||
import android.widget.EditText;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
@ -75,8 +76,10 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
|||
|
||||
}
|
||||
};
|
||||
private ProgressBar progressBar;
|
||||
private RelativeLayout progress;
|
||||
private WebView main_webview;
|
||||
private TextView progressText;
|
||||
private FrameLayout webview_container;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -111,8 +114,9 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
|||
drawMenu();
|
||||
main_webview = findViewById(R.id.main_webview);
|
||||
|
||||
progressBar = findViewById(R.id.progressBar);
|
||||
FrameLayout webview_container = findViewById(R.id.webview_container);
|
||||
progress = findViewById(R.id.progress);
|
||||
progressText = findViewById(R.id.progressText);
|
||||
webview_container = findViewById(R.id.webview_container);
|
||||
final ViewGroup videoLayout = findViewById(R.id.videoLayout);
|
||||
String instance = Helper.getLiveInstance(MainActivity.this);
|
||||
Helper.initializeWebview(MainActivity.this, main_webview);
|
||||
|
@ -171,20 +175,22 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
|||
}
|
||||
|
||||
public void showProgressDialog() {
|
||||
if (progressBar != null) {
|
||||
progressBar.setVisibility(View.VISIBLE);
|
||||
if (progress != null) {
|
||||
progress.setVisibility(View.VISIBLE);
|
||||
webview_container.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
public void hideProgressDialog() {
|
||||
if (progressBar != null) {
|
||||
progressBar.setVisibility(View.GONE);
|
||||
if (progress != null) {
|
||||
progress.setVisibility(View.GONE);
|
||||
webview_container.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
public void setProgressDialog(int progress) {
|
||||
if (progressBar != null) {
|
||||
progressBar.setProgress(progress);
|
||||
if (progressText != null) {
|
||||
progressText.setText(String.format("%s%%", progress));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -13,16 +13,16 @@ package app.fedilab.mobilizon.webview;
|
|||
*
|
||||
* You should have received a copy of the GNU General Public License along with Mobilizon app; if not,
|
||||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.os.Build;
|
||||
import android.provider.Settings;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.webkit.WebResourceError;
|
||||
import android.webkit.WebResourceRequest;
|
||||
import android.webkit.WebResourceResponse;
|
||||
|
@ -46,7 +46,7 @@ public class MobilizonWebViewClient extends WebViewClient {
|
|||
private Activity activity;
|
||||
private CoordinatorLayout rootView;
|
||||
|
||||
public MobilizonWebViewClient(Activity activity) {
|
||||
public MobilizonWebViewClient(Activity activity){
|
||||
this.activity = activity;
|
||||
rootView = activity.findViewById(R.id.main_layout);
|
||||
}
|
||||
|
@ -58,14 +58,15 @@ public class MobilizonWebViewClient extends WebViewClient {
|
|||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public WebResourceResponse shouldInterceptRequest(final WebView view, WebResourceRequest request) {
|
||||
if (request.getUrl().toString().endsWith("api")) {
|
||||
if(request.getUrl().toString().endsWith("api")){
|
||||
Map<String, String> headers = request.getRequestHeaders();
|
||||
Iterator<Map.Entry<String, String>> it = headers.entrySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
Map.Entry<String, String> pair = it.next();
|
||||
if (pair.getKey().compareTo("authorization") == 0 && pair.getValue().startsWith("Bearer")) {
|
||||
if( pair.getKey().compareTo("authorization") == 0 && pair.getValue().startsWith("Bearer")) {
|
||||
MainActivity.isAuthenticated = true;
|
||||
}
|
||||
it.remove();
|
||||
|
@ -76,7 +77,7 @@ public class MobilizonWebViewClient extends WebViewClient {
|
|||
|
||||
@Override
|
||||
public void onPageStarted(WebView view, String url, Bitmap favicon) {
|
||||
MainActivity.isAuthenticated = false;
|
||||
view.setVisibility(View.INVISIBLE);
|
||||
super.onPageStarted(view, url, favicon);
|
||||
if (activity instanceof MainActivity) {
|
||||
((MainActivity) activity).showProgressDialog();
|
||||
|
@ -141,9 +142,9 @@ public class MobilizonWebViewClient extends WebViewClient {
|
|||
|
||||
@Override
|
||||
public void onPageFinished(WebView view, String url) {
|
||||
Log.v(Helper.TAG, "onPageFinished: " + url);
|
||||
Helper.injectCSS(activity, view, "css/style.css");
|
||||
((MainActivity) activity).hideProgressDialog();
|
||||
((MainActivity) activity).drawMenu();
|
||||
((MainActivity)activity).hideProgressDialog();
|
||||
((MainActivity)activity).drawMenu();
|
||||
view.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,33 +4,51 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:paddingBottom="?attr/actionBarSize"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior"
|
||||
tools:context=".MainActivity">
|
||||
<RelativeLayout
|
||||
<FrameLayout
|
||||
android:id="@+id/webview_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<FrameLayout
|
||||
android:id="@+id/webview_container"
|
||||
android:layout_height="match_parent"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
<WebView
|
||||
android:id="@+id/main_webview"
|
||||
android:name="androidx.navigation.fragment.NavHostFragment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
<WebView
|
||||
android:id="@+id/main_webview"
|
||||
android:name="androidx.navigation.fragment.NavHostFragment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
|
||||
/>
|
||||
</FrameLayout>
|
||||
<ProgressBar
|
||||
android:visibility="gone"
|
||||
android:id="@+id/progressBar"
|
||||
style="?android:attr/progressBarStyleHorizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="5dp"
|
||||
/>
|
||||
</FrameLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:visibility="gone"
|
||||
android:id="@+id/progress"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<ProgressBar
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
android:layout_centerInParent="true"
|
||||
android:id="@+id/progressBar"
|
||||
style="?android:attr/indeterminate"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
/>
|
||||
<TextView
|
||||
app:layout_constraintTop_toBottomOf="@+id/progressBar"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
android:layout_width="wrap_content"
|
||||
android:id="@+id/progressText"
|
||||
android:layout_height="wrap_content"/>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</RelativeLayout>
|
||||
|
||||
<!-- View where the video will be shown when video goes fullscreen -->
|
||||
|
|
Loading…
Reference in New Issue