diff --git a/app/src/acad/res/values/strings.xml b/app/src/acad/res/values/strings.xml index 3f0287b..502b19a 100644 --- a/app/src/acad/res/values/strings.xml +++ b/app/src/acad/res/values/strings.xml @@ -235,4 +235,5 @@ Display No opinion Pickup languages + Mise à jour des informations diff --git a/app/src/full/res/values/strings.xml b/app/src/full/res/values/strings.xml index ea7c315..2b30f00 100644 --- a/app/src/full/res/values/strings.xml +++ b/app/src/full/res/values/strings.xml @@ -251,4 +251,5 @@ Pickup categories Pickup languages + Update information \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index e3b217a..574121e 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -117,6 +117,9 @@ android:label="@string/about_the_app" android:windowSoftInputMode="stateAlwaysHidden" /> + diff --git a/app/src/main/java/app/fedilab/fedilabtube/InstancePickerActivity.java b/app/src/main/java/app/fedilab/fedilabtube/InstancePickerActivity.java index e2a07a2..8049963 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/InstancePickerActivity.java +++ b/app/src/main/java/app/fedilab/fedilabtube/InstancePickerActivity.java @@ -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 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)); diff --git a/app/src/main/java/app/fedilab/fedilabtube/MainActivity.java b/app/src/main/java/app/fedilab/fedilabtube/MainActivity.java index 4a69fa8..37c06f9 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/MainActivity.java +++ b/app/src/main/java/app/fedilab/fedilabtube/MainActivity.java @@ -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); diff --git a/app/src/main/java/app/fedilab/fedilabtube/services/RetrieveInfoService.java b/app/src/main/java/app/fedilab/fedilabtube/services/RetrieveInfoService.java new file mode 100644 index 0000000..65c9872 --- /dev/null +++ b/app/src/main/java/app/fedilab/fedilabtube/services/RetrieveInfoService.java @@ -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 . */ + +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; + } +} diff --git a/app/src/main/res/drawable-anydpi-v24/ic_notification_tubelab.xml b/app/src/main/res/drawable-anydpi-v24/ic_notification_tubelab.xml new file mode 100644 index 0000000..4caaeda --- /dev/null +++ b/app/src/main/res/drawable-anydpi-v24/ic_notification_tubelab.xml @@ -0,0 +1,16 @@ + + + + + diff --git a/app/src/main/res/drawable-hdpi/ic_notification_tubelab.png b/app/src/main/res/drawable-hdpi/ic_notification_tubelab.png new file mode 100644 index 0000000..a58f6a5 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_notification_tubelab.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_notification_tubelab.png b/app/src/main/res/drawable-mdpi/ic_notification_tubelab.png new file mode 100644 index 0000000..5cfd622 Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_notification_tubelab.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_notification_tubelab.png b/app/src/main/res/drawable-xhdpi/ic_notification_tubelab.png new file mode 100644 index 0000000..347f385 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_notification_tubelab.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_notification_tubelab.png b/app/src/main/res/drawable-xxhdpi/ic_notification_tubelab.png new file mode 100644 index 0000000..f928b4f Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_notification_tubelab.png differ diff --git a/app/src/main/res/layout/activity_instance_picker.xml b/app/src/main/res/layout/activity_instance_picker.xml index d0d1046..14cb1f0 100644 --- a/app/src/main/res/layout/activity_instance_picker.xml +++ b/app/src/main/res/layout/activity_instance_picker.xml @@ -29,72 +29,101 @@ - -