mirror of
https://framagit.org/tom79/mobilizon-android-app
synced 2025-06-05 21:59:22 +02:00
Display content only when available
This commit is contained in:
@@ -20,7 +20,8 @@ import android.webkit.WebView;
|
|||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.ProgressBar;
|
import android.widget.RelativeLayout;
|
||||||
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
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 WebView main_webview;
|
||||||
|
private TextView progressText;
|
||||||
|
private FrameLayout webview_container;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@@ -111,8 +114,9 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
|||||||
drawMenu();
|
drawMenu();
|
||||||
main_webview = findViewById(R.id.main_webview);
|
main_webview = findViewById(R.id.main_webview);
|
||||||
|
|
||||||
progressBar = findViewById(R.id.progressBar);
|
progress = findViewById(R.id.progress);
|
||||||
FrameLayout webview_container = findViewById(R.id.webview_container);
|
progressText = findViewById(R.id.progressText);
|
||||||
|
webview_container = findViewById(R.id.webview_container);
|
||||||
final ViewGroup videoLayout = findViewById(R.id.videoLayout);
|
final ViewGroup videoLayout = findViewById(R.id.videoLayout);
|
||||||
String instance = Helper.getLiveInstance(MainActivity.this);
|
String instance = Helper.getLiveInstance(MainActivity.this);
|
||||||
Helper.initializeWebview(MainActivity.this, main_webview);
|
Helper.initializeWebview(MainActivity.this, main_webview);
|
||||||
@@ -171,20 +175,22 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void showProgressDialog() {
|
public void showProgressDialog() {
|
||||||
if (progressBar != null) {
|
if (progress != null) {
|
||||||
progressBar.setVisibility(View.VISIBLE);
|
progress.setVisibility(View.VISIBLE);
|
||||||
|
webview_container.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void hideProgressDialog() {
|
public void hideProgressDialog() {
|
||||||
if (progressBar != null) {
|
if (progress != null) {
|
||||||
progressBar.setVisibility(View.GONE);
|
progress.setVisibility(View.GONE);
|
||||||
|
webview_container.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setProgressDialog(int progress) {
|
public void setProgressDialog(int progress) {
|
||||||
if (progressBar != null) {
|
if (progressText != null) {
|
||||||
progressBar.setProgress(progress);
|
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,
|
* You should have received a copy of the GNU General Public License along with Mobilizon app; if not,
|
||||||
* see <http://www.gnu.org/licenses>. */
|
* see <http://www.gnu.org/licenses>. */
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
import android.net.NetworkInfo;
|
import android.net.NetworkInfo;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.util.Log;
|
import android.view.View;
|
||||||
import android.webkit.WebResourceError;
|
import android.webkit.WebResourceError;
|
||||||
import android.webkit.WebResourceRequest;
|
import android.webkit.WebResourceRequest;
|
||||||
import android.webkit.WebResourceResponse;
|
import android.webkit.WebResourceResponse;
|
||||||
@@ -58,6 +58,7 @@ public class MobilizonWebViewClient extends WebViewClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WebResourceResponse shouldInterceptRequest(final WebView view, WebResourceRequest request) {
|
public WebResourceResponse shouldInterceptRequest(final WebView view, WebResourceRequest request) {
|
||||||
if(request.getUrl().toString().endsWith("api")){
|
if(request.getUrl().toString().endsWith("api")){
|
||||||
@@ -76,7 +77,7 @@ public class MobilizonWebViewClient extends WebViewClient {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPageStarted(WebView view, String url, Bitmap favicon) {
|
public void onPageStarted(WebView view, String url, Bitmap favicon) {
|
||||||
MainActivity.isAuthenticated = false;
|
view.setVisibility(View.INVISIBLE);
|
||||||
super.onPageStarted(view, url, favicon);
|
super.onPageStarted(view, url, favicon);
|
||||||
if (activity instanceof MainActivity) {
|
if (activity instanceof MainActivity) {
|
||||||
((MainActivity) activity).showProgressDialog();
|
((MainActivity) activity).showProgressDialog();
|
||||||
@@ -141,9 +142,9 @@ public class MobilizonWebViewClient extends WebViewClient {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPageFinished(WebView view, String url) {
|
public void onPageFinished(WebView view, String url) {
|
||||||
Log.v(Helper.TAG, "onPageFinished: " + url);
|
|
||||||
Helper.injectCSS(activity, view, "css/style.css");
|
Helper.injectCSS(activity, view, "css/style.css");
|
||||||
((MainActivity)activity).hideProgressDialog();
|
((MainActivity)activity).hideProgressDialog();
|
||||||
((MainActivity)activity).drawMenu();
|
((MainActivity)activity).drawMenu();
|
||||||
|
view.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -4,11 +4,9 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:paddingBottom="?attr/actionBarSize"
|
||||||
app:layout_behavior="@string/appbar_scrolling_view_behavior"
|
app:layout_behavior="@string/appbar_scrolling_view_behavior"
|
||||||
tools:context=".MainActivity">
|
tools:context=".MainActivity">
|
||||||
<RelativeLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent">
|
|
||||||
<FrameLayout
|
<FrameLayout
|
||||||
android:id="@+id/webview_container"
|
android:id="@+id/webview_container"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
@@ -21,16 +19,36 @@
|
|||||||
android:name="androidx.navigation.fragment.NavHostFragment"
|
android:name="androidx.navigation.fragment.NavHostFragment"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
|
|
||||||
/>
|
/>
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
<ProgressBar
|
|
||||||
|
<RelativeLayout
|
||||||
android:visibility="gone"
|
android:visibility="gone"
|
||||||
android:id="@+id/progressBar"
|
android:id="@+id/progress"
|
||||||
style="?android:attr/progressBarStyleHorizontal"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="5dp"
|
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>
|
</RelativeLayout>
|
||||||
|
|
||||||
<!-- View where the video will be shown when video goes fullscreen -->
|
<!-- View where the video will be shown when video goes fullscreen -->
|
||||||
|
Reference in New Issue
Block a user