mirror of
https://framagit.org/tom79/fedilab-tube
synced 2025-02-03 04:37:50 +01:00
Update info via a service
This commit is contained in:
parent
015a2f3289
commit
7aab6fbba9
@ -235,4 +235,5 @@
|
||||
<string name="display">Display</string>
|
||||
<string name="no_opinion">No opinion</string>
|
||||
<string name="pickup_languages">Pickup languages</string>
|
||||
<string name="notification_channel_name">Mise à jour des informations</string>
|
||||
</resources>
|
||||
|
@ -251,4 +251,5 @@
|
||||
|
||||
<string name="pickup_categories">Pickup categories</string>
|
||||
<string name="pickup_languages">Pickup languages</string>
|
||||
<string name="notification_channel_name">Update information</string>
|
||||
</resources>
|
@ -117,6 +117,9 @@
|
||||
android:label="@string/about_the_app"
|
||||
android:windowSoftInputMode="stateAlwaysHidden" />
|
||||
|
||||
<service
|
||||
android:name=".services.RetrieveInfoService"
|
||||
android:exported="false" />
|
||||
<receiver
|
||||
android:name=".services.PeertubeUploadReceiver"
|
||||
android:exported="false">
|
||||
|
@ -44,6 +44,7 @@ import app.fedilab.fedilabtube.client.APIResponse;
|
||||
import app.fedilab.fedilabtube.client.entities.Instance;
|
||||
import app.fedilab.fedilabtube.client.entities.InstanceParams;
|
||||
import app.fedilab.fedilabtube.drawer.InstanceAdapter;
|
||||
import app.fedilab.fedilabtube.helper.Helper;
|
||||
import app.fedilab.fedilabtube.helper.RoundedBackgroundSpan;
|
||||
import app.fedilab.fedilabtube.viewmodel.InstancesVM;
|
||||
import es.dmoral.toasty.Toasty;
|
||||
@ -160,6 +161,11 @@ public class InstancePickerActivity extends AppCompatActivity {
|
||||
}
|
||||
instanceParams.setLanguagesOr(langs);
|
||||
languages_view.setText(stringBuilder, TextView.BufferType.SPANNABLE);
|
||||
if (languages_view.getText().toString().trim().length() > 0) {
|
||||
languages_view.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
languages_view.setVisibility(View.GONE);
|
||||
}
|
||||
mainLoader.setVisibility(View.VISIBLE);
|
||||
viewModel.getInstances(instanceParams).observe(InstancePickerActivity.this, this::manageVIewInstance);
|
||||
});
|
||||
@ -218,6 +224,11 @@ public class InstancePickerActivity extends AppCompatActivity {
|
||||
}
|
||||
instanceParams.setCategoriesOr(cats);
|
||||
categories_view.setText(stringBuilder, TextView.BufferType.SPANNABLE);
|
||||
if (categories_view.getText().toString().trim().length() > 0) {
|
||||
categories_view.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
categories_view.setVisibility(View.GONE);
|
||||
}
|
||||
mainLoader.setVisibility(View.VISIBLE);
|
||||
viewModel.getInstances(instanceParams).observe(InstancePickerActivity.this, this::manageVIewInstance);
|
||||
});
|
||||
@ -257,11 +268,13 @@ public class InstancePickerActivity extends AppCompatActivity {
|
||||
return;
|
||||
}
|
||||
List<Instance> instances = apiResponse.getInstances();
|
||||
RecyclerView lv_instances = findViewById(R.id.lv_instances);
|
||||
if ((instances == null || instances.size() == 0)) {
|
||||
textviewNoAction.setVisibility(View.VISIBLE);
|
||||
lv_instances.setVisibility(View.GONE);
|
||||
} else {
|
||||
textviewNoAction.setVisibility(View.GONE);
|
||||
RecyclerView lv_instances = findViewById(R.id.lv_instances);
|
||||
lv_instances.setVisibility(View.VISIBLE);
|
||||
InstanceAdapter instanceAdapter = new InstanceAdapter(instances);
|
||||
lv_instances.setAdapter(instanceAdapter);
|
||||
lv_instances.setLayoutManager(new LinearLayoutManager(InstancePickerActivity.this));
|
||||
|
@ -20,6 +20,7 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
@ -42,14 +43,12 @@ import com.google.android.material.bottomnavigation.BottomNavigationView;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
import app.fedilab.fedilabtube.client.HttpsConnection;
|
||||
import app.fedilab.fedilabtube.client.PeertubeAPI;
|
||||
import app.fedilab.fedilabtube.client.entities.Account;
|
||||
import app.fedilab.fedilabtube.client.entities.InstanceNodeInfo;
|
||||
import app.fedilab.fedilabtube.client.entities.PeertubeInformation;
|
||||
import app.fedilab.fedilabtube.helper.Helper;
|
||||
import app.fedilab.fedilabtube.services.RetrieveInfoService;
|
||||
import app.fedilab.fedilabtube.sqlite.AccountDAO;
|
||||
import app.fedilab.fedilabtube.sqlite.Sqlite;
|
||||
import app.fedilab.fedilabtube.viewmodel.FeedsVM;
|
||||
@ -67,6 +66,8 @@ public class MainActivity extends AppCompatActivity {
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
|
||||
BottomNavigationView navView = findViewById(R.id.nav_view);
|
||||
|
||||
if (Helper.isLoggedIn(MainActivity.this)) {
|
||||
@ -75,23 +76,6 @@ public class MainActivity extends AppCompatActivity {
|
||||
navView.inflateMenu(R.menu.bottom_nav_menu);
|
||||
}
|
||||
|
||||
if (peertubeInformation == null) {
|
||||
peertubeInformation = new PeertubeInformation();
|
||||
peertubeInformation.setCategories(new LinkedHashMap<>());
|
||||
peertubeInformation.setLanguages(new LinkedHashMap<>());
|
||||
peertubeInformation.setLicences(new LinkedHashMap<>());
|
||||
peertubeInformation.setPrivacies(new LinkedHashMap<>());
|
||||
peertubeInformation.setPlaylistPrivacies(new LinkedHashMap<>());
|
||||
peertubeInformation.setTranslations(new LinkedHashMap<>());
|
||||
new Thread(() -> {
|
||||
try {
|
||||
peertubeInformation = new PeertubeAPI(MainActivity.this).getPeertubeInformation();
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
// Passing each menu ID as a set of Ids because each
|
||||
// menu should be considered as top level destinations.
|
||||
AppBarConfiguration appBarConfiguration;
|
||||
@ -107,6 +91,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
.build();
|
||||
}
|
||||
|
||||
startInForeground();
|
||||
NavHostFragment navHostFragment = (NavHostFragment) getSupportFragmentManager().findFragmentById(R.id.nav_host_fragment);
|
||||
if (navHostFragment != null) {
|
||||
NavInflater inflater = navHostFragment.getNavController().getNavInflater();
|
||||
@ -124,6 +109,16 @@ public class MainActivity extends AppCompatActivity {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void startInForeground() {
|
||||
Intent notificationIntent = new Intent(this, RetrieveInfoService.class);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
startForegroundService(notificationIntent);
|
||||
} else {
|
||||
startService(notificationIntent);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(@NotNull Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.main_menu, menu);
|
||||
|
@ -0,0 +1,95 @@
|
||||
package app.fedilab.fedilabtube.services;
|
||||
/* Copyright 2020 Thomas Schneider
|
||||
*
|
||||
* This file is a part of TubeLab
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
||||
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* TubeLab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||
* Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with TubeLab; if not,
|
||||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
import android.app.Notification;
|
||||
import android.app.Service;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.os.IBinder;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.app.NotificationCompat;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
import app.fedilab.fedilabtube.R;
|
||||
import app.fedilab.fedilabtube.client.HttpsConnection;
|
||||
import app.fedilab.fedilabtube.client.PeertubeAPI;
|
||||
import app.fedilab.fedilabtube.client.entities.PeertubeInformation;
|
||||
|
||||
import static app.fedilab.fedilabtube.MainActivity.peertubeInformation;
|
||||
|
||||
|
||||
public class RetrieveInfoService extends Service {
|
||||
|
||||
static String NOTIFICATION_CHANNEL_ID = "update_info";
|
||||
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
Notification.Builder builder = new Notification.Builder(this, NOTIFICATION_CHANNEL_ID)
|
||||
.setSmallIcon(R.drawable.ic_notification_tubelab)
|
||||
.setContentTitle(getString(R.string.app_name))
|
||||
.setContentText(getString(R.string.notification_channel_name))
|
||||
.setAutoCancel(true);
|
||||
|
||||
Notification notification = builder.build();
|
||||
startForeground(1, notification);
|
||||
|
||||
} else {
|
||||
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID)
|
||||
.setContentTitle(getString(R.string.app_name))
|
||||
.setContentText(getString(R.string.notification_channel_name))
|
||||
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
|
||||
.setAutoCancel(true);
|
||||
|
||||
Notification notification = builder.build();
|
||||
|
||||
startForeground(1, notification);
|
||||
}
|
||||
Thread thread = new Thread() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
peertubeInformation = new PeertubeInformation();
|
||||
peertubeInformation.setCategories(new LinkedHashMap<>());
|
||||
peertubeInformation.setLanguages(new LinkedHashMap<>());
|
||||
peertubeInformation.setLicences(new LinkedHashMap<>());
|
||||
peertubeInformation.setPrivacies(new LinkedHashMap<>());
|
||||
peertubeInformation.setPlaylistPrivacies(new LinkedHashMap<>());
|
||||
peertubeInformation.setTranslations(new LinkedHashMap<>());
|
||||
try {
|
||||
peertubeInformation = new PeertubeAPI(RetrieveInfoService.this).getPeertubeInformation();
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
stopForeground(true);
|
||||
|
||||
}
|
||||
};
|
||||
thread.start();
|
||||
|
||||
return START_NOT_STICKY;
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IBinder onBind(Intent intent) {
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:tint="#FFFFFF"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<group
|
||||
android:scaleX="1.104"
|
||||
android:scaleY="1.104"
|
||||
android:translateX="-1.248"
|
||||
android:translateY="-1.248">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M10,16.5l6,-4.5 -6,-4.5v9zM12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM12,20c-4.41,0 -8,-3.59 -8,-8s3.59,-8 8,-8 8,3.59 8,8 -3.59,8 -8,8z" />
|
||||
</group>
|
||||
</vector>
|
BIN
app/src/main/res/drawable-hdpi/ic_notification_tubelab.png
Normal file
BIN
app/src/main/res/drawable-hdpi/ic_notification_tubelab.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 499 B |
BIN
app/src/main/res/drawable-mdpi/ic_notification_tubelab.png
Normal file
BIN
app/src/main/res/drawable-mdpi/ic_notification_tubelab.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 359 B |
BIN
app/src/main/res/drawable-xhdpi/ic_notification_tubelab.png
Normal file
BIN
app/src/main/res/drawable-xhdpi/ic_notification_tubelab.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 614 B |
BIN
app/src/main/res/drawable-xxhdpi/ic_notification_tubelab.png
Normal file
BIN
app/src/main/res/drawable-xxhdpi/ic_notification_tubelab.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 905 B |
@ -29,72 +29,101 @@
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:id="@+id/filters_container"
|
||||
>
|
||||
<Button
|
||||
android:id="@+id/pickup_categories"
|
||||
style="@style/Base.Widget.AppCompat.Button.Colored"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:text="@string/pickup_categories"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
/>
|
||||
<Button
|
||||
android:id="@+id/pickup_languages"
|
||||
style="@style/Base.Widget.AppCompat.Button.Colored"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:text="@string/pickup_languages"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@id/pickup_categories"
|
||||
/>
|
||||
android:padding="@dimen/fab_margin">
|
||||
|
||||
<TextView
|
||||
android:layout_marginTop="5dp"
|
||||
app:layout_constraintTop_toBottomOf="@+id/pickup_categories"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
android:id="@+id/categories_view"
|
||||
<androidx.cardview.widget.CardView
|
||||
android:id="@+id/filters_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:drawableStartCompat="@drawable/ic_baseline_category_24" />
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<TextView
|
||||
android:layout_marginTop="5dp"
|
||||
app:layout_constraintTop_toBottomOf="@+id/categories_view"
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<Button
|
||||
android:id="@+id/pickup_categories"
|
||||
style="@style/Base.Widget.AppCompat.Button.Colored"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:text="@string/pickup_categories"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/pickup_languages"
|
||||
style="@style/Base.Widget.AppCompat.Button.Colored"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:text="@string/pickup_languages"
|
||||
app:layout_constraintStart_toEndOf="@id/pickup_categories"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/categories_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="5dp"
|
||||
android:drawablePadding="5dp"
|
||||
android:visibility="gone"
|
||||
app:drawableStartCompat="@drawable/ic_baseline_category_24"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/pickup_categories" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/languages_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="5dp"
|
||||
android:drawablePadding="5dp"
|
||||
android:visibility="gone"
|
||||
app:drawableStartCompat="@drawable/ic_baseline_forum_24"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/categories_view" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_spinner"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="14dp"
|
||||
android:labelFor="@+id/sensitive"
|
||||
android:text="@string/sensitive_video"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/languages_view" />
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/sensitive"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="10dp"
|
||||
app:layout_constraintStart_toEndOf="@+id/text_spinner"
|
||||
app:layout_constraintTop_toBottomOf="@+id/languages_view" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</androidx.cardview.widget.CardView>
|
||||
<!-- Main Loader -->
|
||||
<RelativeLayout
|
||||
android:id="@+id/loader"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:gravity="center"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
android:id="@+id/languages_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:drawableStartCompat="@drawable/ic_baseline_forum_24"/>
|
||||
app:layout_constraintTop_toBottomOf="@+id/filters_container">
|
||||
|
||||
<TextView
|
||||
android:layout_marginTop="14dp"
|
||||
android:id="@+id/text_spinner"
|
||||
app:layout_constraintTop_toBottomOf="@+id/languages_view"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/sensitive_video"
|
||||
android:labelFor="@+id/sensitive"/>
|
||||
<ProgressBar
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:indeterminate="true" />
|
||||
</RelativeLayout>
|
||||
|
||||
<Spinner
|
||||
app:layout_constraintTop_toBottomOf="@+id/languages_view"
|
||||
app:layout_constraintStart_toEndOf="@+id/text_spinner"
|
||||
android:id="@+id/sensitive"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="10dp" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
<LinearLayout
|
||||
app:layout_constraintTop_toBottomOf="@+id/filters_container"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
@ -103,8 +132,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_height="0dp"
|
||||
android:orientation="vertical"
|
||||
>
|
||||
android:orientation="vertical">
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/lv_instances"
|
||||
@ -127,33 +155,6 @@
|
||||
android:text="@string/action_instance_empty_content"
|
||||
android:textSize="25sp" />
|
||||
</RelativeLayout>
|
||||
<!-- Main Loader -->
|
||||
<RelativeLayout
|
||||
android:id="@+id/loader"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
android:visibility="gone">
|
||||
|
||||
<ProgressBar
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:indeterminate="true" />
|
||||
</RelativeLayout>
|
||||
<!-- Loader for next status -->
|
||||
<RelativeLayout
|
||||
android:id="@+id/loading_next_status"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="20dp"
|
||||
android:layout_gravity="bottom|center_horizontal"
|
||||
android:gravity="bottom|center_horizontal"
|
||||
android:visibility="gone">
|
||||
|
||||
<ProgressBar
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:indeterminate="true" />
|
||||
</RelativeLayout>
|
||||
</LinearLayout>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
|
Loading…
x
Reference in New Issue
Block a user