loading indicator and notfication attempt

This commit is contained in:
Benedek László 2024-05-08 21:56:15 +02:00
parent 255f69ad8f
commit affdd3e4fb
7 changed files with 66 additions and 3 deletions

View File

@ -2,6 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
@ -30,5 +32,4 @@
</intent-filter>
</activity>
</application>
</manifest>

View File

@ -1,11 +1,13 @@
package com.dowerx.quack.fragment;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@ -25,7 +27,7 @@ import java.util.List;
public class FeedFragment extends Fragment implements LoaderManager.LoaderCallbacks<List<Post>> {
private RecyclerView recyclerView;
Dialog progress;
public FeedFragment() {
}
@ -62,6 +64,10 @@ public class FeedFragment extends Fragment implements LoaderManager.LoaderCallba
@Override
public Loader<List<Post>> onCreateLoader(int id, @Nullable Bundle args) {
Log.d(this.getClass().getName(), "onCreateLoader");
progress = new Dialog(getContext());
progress.requestWindowFeature(Window.FEATURE_NO_TITLE);
progress.setContentView(R.layout.loading);
progress.show();
return new PostService.GetFeed(getContext());
}
@ -69,6 +75,7 @@ public class FeedFragment extends Fragment implements LoaderManager.LoaderCallba
public void onLoadFinished(@NonNull Loader<List<Post>> loader, List<Post> data) {
Log.d(this.getClass().getName(), "onLoadFinished");
Log.d(this.getClass().getName(), data.toString());
progress.cancel();
recyclerView.setAdapter(new PostRecyclerViewAdapter(data, (SwitcherActivity)getContext()));
}

View File

@ -1,9 +1,11 @@
package com.dowerx.quack.fragment;
import android.app.Dialog;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.TextView;
import androidx.annotation.NonNull;
@ -20,6 +22,8 @@ import com.dowerx.quack.service.UserService;
public class ProfileFragment extends Fragment implements LoaderManager.LoaderCallbacks<User> {
private Dialog progress;
private static final String ID = "id";
private String id;
@ -60,11 +64,16 @@ public class ProfileFragment extends Fragment implements LoaderManager.LoaderCal
@NonNull
@Override
public Loader<User> onCreateLoader(int id, @Nullable Bundle args) {
progress = new Dialog(getContext());
progress.requestWindowFeature(Window.FEATURE_NO_TITLE);
progress.setContentView(R.layout.loading);
progress.show();
return new UserService.GetUserById(getContext(), this.id);
}
@Override
public void onLoadFinished(@NonNull Loader<User> loader, User data) {
progress.cancel();
((TextView)view.findViewById(R.id.profile_username)).setText(data.getUsername());
getParentFragmentManager()
.beginTransaction()

View File

@ -1,10 +1,12 @@
package com.dowerx.quack.fragment;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.EditText;
import androidx.annotation.NonNull;
@ -24,6 +26,8 @@ import java.util.List;
public class SearchFragment extends Fragment implements LoaderManager.LoaderCallbacks<List<User>> {
private Dialog progress;
private RecyclerView recyclerView;
private EditText query;
@ -68,11 +72,16 @@ public class SearchFragment extends Fragment implements LoaderManager.LoaderCall
@NonNull
@Override
public Loader<List<User>> onCreateLoader(int id, @Nullable Bundle args) {
progress = new Dialog(getContext());
progress.requestWindowFeature(Window.FEATURE_NO_TITLE);
progress.setContentView(R.layout.loading);
progress.show();
return new UserService.SearchUsername(query.getText().toString(), getContext());
}
@Override
public void onLoadFinished(@NonNull Loader<List<User>> loader, List<User> data) {
progress.cancel();
recyclerView.setAdapter(new UserRecyclerViewAdapter(data, (SwitcherActivity) getContext()));
}

View File

@ -1,10 +1,20 @@
package com.dowerx.quack.service;
import android.Manifest;
import android.app.Activity;
import android.app.NotificationManager;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.AsyncTask;
import android.os.Build;
import android.widget.Toast;
import androidx.annotation.RequiresApi;
import androidx.core.app.ActivityCompat;
import androidx.core.app.NotificationCompat;
import com.dowerx.quack.R;
import com.dowerx.quack.activity.MainActivity;
import com.dowerx.quack.activity.SwitcherActivity;
import com.google.android.gms.tasks.Tasks;
@ -85,6 +95,7 @@ public class AuthService {
}
}
@RequiresApi(api = Build.VERSION_CODES.TIRAMISU)
@Override
protected void onPostExecute(Boolean result) {
if (result) {
@ -92,6 +103,22 @@ public class AuthService {
toast.setText("succesful register");
toast.setDuration(Toast.LENGTH_LONG);
toast.show();
NotificationCompat.Builder builder = new NotificationCompat.Builder(activity.getApplicationContext(), "register")
.setSmallIcon(R.mipmap.ic_launcher_round)
.setContentTitle("Welcome to Quack!")
.setContentText("Thank you for registering!")
.setPriority(NotificationCompat.PRIORITY_LOW);
if (ActivityCompat.checkSelfPermission(activity.getApplicationContext(), Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) {
String[] permissions = new String[1];
permissions[0] = Manifest.permission.POST_NOTIFICATIONS;
ActivityCompat.requestPermissions(activity, permissions, 0);
}
NotificationManager manager = (NotificationManager) activity.getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
manager.notify(0, builder.build());
activity.startActivity(new Intent(activity, MainActivity.class));
} else {
Toast toast = new Toast(activity.getBaseContext());

View File

@ -71,7 +71,6 @@ public class PostService {
} catch (ExecutionException | InterruptedException e) {
throw new RuntimeException(e);
}
return posts;
}

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</androidx.cardview.widget.CardView>