diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 33a7970..89a63fc 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -2,6 +2,8 @@ + + - \ No newline at end of file diff --git a/app/src/main/java/com/dowerx/quack/fragment/FeedFragment.java b/app/src/main/java/com/dowerx/quack/fragment/FeedFragment.java index ad2f03c..e08ab36 100644 --- a/app/src/main/java/com/dowerx/quack/fragment/FeedFragment.java +++ b/app/src/main/java/com/dowerx/quack/fragment/FeedFragment.java @@ -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> { private RecyclerView recyclerView; - + Dialog progress; public FeedFragment() { } @@ -62,6 +64,10 @@ public class FeedFragment extends Fragment implements LoaderManager.LoaderCallba @Override public Loader> 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> loader, List data) { Log.d(this.getClass().getName(), "onLoadFinished"); Log.d(this.getClass().getName(), data.toString()); + progress.cancel(); recyclerView.setAdapter(new PostRecyclerViewAdapter(data, (SwitcherActivity)getContext())); } diff --git a/app/src/main/java/com/dowerx/quack/fragment/ProfileFragment.java b/app/src/main/java/com/dowerx/quack/fragment/ProfileFragment.java index f7285b9..cdc52e6 100644 --- a/app/src/main/java/com/dowerx/quack/fragment/ProfileFragment.java +++ b/app/src/main/java/com/dowerx/quack/fragment/ProfileFragment.java @@ -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 { + 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 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 loader, User data) { + progress.cancel(); ((TextView)view.findViewById(R.id.profile_username)).setText(data.getUsername()); getParentFragmentManager() .beginTransaction() diff --git a/app/src/main/java/com/dowerx/quack/fragment/SearchFragment.java b/app/src/main/java/com/dowerx/quack/fragment/SearchFragment.java index d2c5bc4..22f4356 100644 --- a/app/src/main/java/com/dowerx/quack/fragment/SearchFragment.java +++ b/app/src/main/java/com/dowerx/quack/fragment/SearchFragment.java @@ -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> { + 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> 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> loader, List data) { + progress.cancel(); recyclerView.setAdapter(new UserRecyclerViewAdapter(data, (SwitcherActivity) getContext())); } diff --git a/app/src/main/java/com/dowerx/quack/service/AuthService.java b/app/src/main/java/com/dowerx/quack/service/AuthService.java index 006c613..4d53101 100644 --- a/app/src/main/java/com/dowerx/quack/service/AuthService.java +++ b/app/src/main/java/com/dowerx/quack/service/AuthService.java @@ -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()); diff --git a/app/src/main/java/com/dowerx/quack/service/PostService.java b/app/src/main/java/com/dowerx/quack/service/PostService.java index dedabaa..88fd5dc 100644 --- a/app/src/main/java/com/dowerx/quack/service/PostService.java +++ b/app/src/main/java/com/dowerx/quack/service/PostService.java @@ -71,7 +71,6 @@ public class PostService { } catch (ExecutionException | InterruptedException e) { throw new RuntimeException(e); } - return posts; } diff --git a/app/src/main/res/layout/loading.xml b/app/src/main/res/layout/loading.xml new file mode 100644 index 0000000..d591931 --- /dev/null +++ b/app/src/main/res/layout/loading.xml @@ -0,0 +1,11 @@ + + + + \ No newline at end of file