Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP Feat: Friending Feature #484

Open
wants to merge 17 commits into
base: friending
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
6fb1ee4
displays friended users, friend requests and lets adding new friends
balaji-ramavathu Jul 9, 2019
025ccd7
shows request status, adding new friend from floating button
balaji-ramavathu Jul 17, 2019
8e2ceac
adds delete friend user, delete and resend friend request options
balaji-ramavathu Jul 20, 2019
84ba455
adds resend friend request option
balaji-ramavathu Jul 20, 2019
43baf12
changes pojo files according to changed json format from test server
balaji-ramavathu Jul 27, 2019
12e0632
updates friend requests list after adding new friend request
balaji-ramavathu Jul 28, 2019
2dbd392
fixes failed travis build
balaji-ramavathu Jul 28, 2019
5c80de1
Fix: Unable to make HTTP requests in Android Pie (#482)
balaji-ramavathu Jul 30, 2019
d953773
displays friended users, friend requests and lets adding new friends
balaji-ramavathu Jul 9, 2019
4c32a9a
shows request status, adding new friend from floating button
balaji-ramavathu Jul 17, 2019
a5c879b
adds delete friend user, delete and resend friend request options
balaji-ramavathu Jul 20, 2019
fa13dbb
adds resend friend request option
balaji-ramavathu Jul 20, 2019
6b06282
changes pojo files according to changed json format from test server
balaji-ramavathu Jul 27, 2019
8ec8461
updates friend requests list after adding new friend request
balaji-ramavathu Jul 28, 2019
35dc166
fixes failed travis build
balaji-ramavathu Jul 28, 2019
874900b
Merge branch 'friending' of https://github.com/balaji-ramavathu/andro…
balaji-ramavathu Aug 9, 2019
c712a8e
removes adding,deleting,resending friend users,requests
balaji-ramavathu Aug 9, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ before_install:

jdk:
- oraclejdk8
- oraclejdk9
- oraclejdk11

sudo: required
android:
Expand Down
3 changes: 3 additions & 0 deletions src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
android:label="@string/application_name"
android:resizeableActivity="true"
android:theme="@style/Theme.Amahi"
android:usesCleartextTraffic="true"
tools:ignore="GoogleAppIndexingWarning">
<provider
android:name="androidx.core.content.FileProvider"
Expand Down Expand Up @@ -222,6 +223,8 @@

<activity android:name=".activity.OfflineFilesActivity" />
<activity android:name=".activity.RecentFilesActivity"></activity>
<activity android:name=".activity.FriendsActivity"
android:theme="@style/Theme.Amahi.Friends"></activity>
</application>

</manifest>
8 changes: 7 additions & 1 deletion src/main/java/org/amahi/anywhere/AmahiModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import android.content.Context;

import org.amahi.anywhere.activity.AuthenticationActivity;
import org.amahi.anywhere.activity.FriendsActivity;
import org.amahi.anywhere.activity.NativeVideoActivity;
import org.amahi.anywhere.activity.NavigationActivity;
import org.amahi.anywhere.activity.OfflineFilesActivity;
Expand All @@ -35,6 +36,8 @@
import org.amahi.anywhere.activity.ServerFilesActivity;
import org.amahi.anywhere.cache.CacheModule;
import org.amahi.anywhere.fragment.AudioListFragment;
import org.amahi.anywhere.fragment.FriendRequestsFragment;
import org.amahi.anywhere.fragment.FriendsFragment;
import org.amahi.anywhere.fragment.NavigationFragment;
import org.amahi.anywhere.fragment.ServerAppsFragment;
import org.amahi.anywhere.fragment.ServerFileAudioFragment;
Expand Down Expand Up @@ -107,7 +110,10 @@
TvPlaybackVideoActivity.class,
TvPlaybackAudioActivity.class,
TvPlaybackAudioFragment.class,
AudioMetadataRetrievingTask.class
AudioMetadataRetrievingTask.class,
FriendsFragment.class,
FriendRequestsFragment.class,
FriendsActivity.class
}
)
class AmahiModule {
Expand Down
121 changes: 121 additions & 0 deletions src/main/java/org/amahi/anywhere/activity/FriendsActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
package org.amahi.anywhere.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import android.os.Bundle;
import android.view.MenuItem;

import com.google.android.material.tabs.TabLayout;

import org.amahi.anywhere.AmahiApplication;
import org.amahi.anywhere.R;
import org.amahi.anywhere.adapter.FriendsPagerAdapter;
import org.amahi.anywhere.bus.BusProvider;
import org.amahi.anywhere.fragment.FriendRequestsFragment;
import org.amahi.anywhere.fragment.FriendsFragment;
import org.amahi.anywhere.server.client.ServerClient;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

public class FriendsActivity extends AppCompatActivity {

@Inject
ServerClient serverClient;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_friends);

setUpHomeNavigation();

setUpInjections();

setUpPager();

getTabLayout().setupWithViewPager(getPager());


}

private void setUpInjections() {
AmahiApplication.from(this).inject(this);
}

private void setUpHomeNavigation() {
getSupportActionBar().setTitle("Friends");
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}

private void setUpPager() {

List<Fragment> fragmentList = getFragments();

List<String> fragmentTitles = getFragmentTitles();

FriendsPagerAdapter adapter = new FriendsPagerAdapter(getSupportFragmentManager(), fragmentList, fragmentTitles);
getPager().setAdapter(adapter);
}

@Override
public boolean onOptionsItemSelected(MenuItem menuItem) {
switch (menuItem.getItemId()) {
case android.R.id.home:
onBackPressed();
return true;

default:
return super.onOptionsItemSelected(menuItem);
}
}

private List<Fragment> getFragments() {

Fragment friendsFragment = new FriendsFragment();
Fragment friendRequestsFragment = new FriendRequestsFragment();
List<Fragment> fragmentList = new ArrayList<>();
fragmentList.add(friendsFragment);
fragmentList.add(friendRequestsFragment);

return fragmentList;
}

private List<String> getFragmentTitles() {

List<String> fragmentTitles = new ArrayList<>();
fragmentTitles.add("Friends");
fragmentTitles.add("Friend Requests");

return fragmentTitles;
}

private ViewPager getPager() {
return findViewById(R.id.pager_friends);
}

private TabLayout getTabLayout() {
return findViewById(R.id.tablayout_friends);
}


@Override
public void onResume() {
super.onResume();

BusProvider.getBus().register(this);
}

@Override
public void onPause() {
super.onPause();

BusProvider.getBus().unregister(this);
}

}
18 changes: 18 additions & 0 deletions src/main/java/org/amahi/anywhere/activity/NavigationActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.drawerlayout.widget.DrawerLayout;
Expand All @@ -30,6 +31,7 @@
import androidx.appcompat.app.AppCompatDelegate;
import androidx.appcompat.widget.Toolbar;
import androidx.core.view.GravityCompat;

import android.view.MenuItem;
import android.view.View;
import android.view.ViewStub;
Expand All @@ -43,6 +45,7 @@
import org.amahi.anywhere.bus.AppSelectedEvent;
import org.amahi.anywhere.bus.AppsSelectedEvent;
import org.amahi.anywhere.bus.BusProvider;
import org.amahi.anywhere.bus.FriendsSelectedEvent;
import org.amahi.anywhere.bus.OfflineFilesSelectedEvent;
import org.amahi.anywhere.bus.RecentFilesSelectedEvent;
import org.amahi.anywhere.bus.SettingsSelectedEvent;
Expand Down Expand Up @@ -345,6 +348,21 @@ private void showRecentFiles() {
startActivity(intent);
}

@Subscribe
public void onFriendsSelected(FriendsSelectedEvent event) {

showFriends();

if (isNavigationDrawerAvailable()) {
hideNavigationDrawer();
}
}

private void showFriends() {
Intent intent = Intents.Builder.with(this).buildFriendsActivity();
startActivity(intent);
}

@Subscribe
public void onShareSelected(ShareSelectedEvent event) {
setUpShare(event.getShare());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package org.amahi.anywhere.adapter;

import android.content.Context;
import android.graphics.drawable.GradientDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import org.amahi.anywhere.R;
import org.amahi.anywhere.server.model.FriendRequestItem;

import java.util.List;

public class FriendRequestsListAdapter extends RecyclerView.Adapter<FriendRequestsListAdapter.FriendRequestsListViewHolder> {
private List<FriendRequestItem> friendRequestsList;
private Context context;

public FriendRequestsListAdapter(Context context, List<FriendRequestItem> friendRequestsList) {
this.context = context;
this.friendRequestsList = friendRequestsList;

}


@NonNull
@Override
public FriendRequestsListViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return new FriendRequestsListViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.friend_requests_list_item, parent, false));
}

@Override
public void onBindViewHolder(@NonNull FriendRequestsListViewHolder holder, int position) {
holder.friendEmailText.setText(friendRequestsList.get(position).getEmail());
int status = friendRequestsList.get(position).getStatus();

//set status text and color based on status value
String statusText = "Active";
int colorResourceId = R.color.status_active;
switch (status) {
case 0:
statusText = "Active";
colorResourceId = R.color.status_active;
break;
case 1:
statusText = "Expired";
colorResourceId = R.color.status_expired;
break;
case 2:
statusText = "Accepted";
colorResourceId = R.color.status_accepted;
break;
case 3:
statusText = "Rejected";
colorResourceId = R.color.status_rejected;
break;

}
holder.friendRequestStatus.setText(statusText);
GradientDrawable drawable = (GradientDrawable) holder.friendRequestStatus.getBackground();
drawable.setColor(context.getResources().getColor(colorResourceId));
holder.friendRequestStatus.setBackground(drawable);

}

@Override
public int getItemCount() {
return friendRequestsList.size();
}

class FriendRequestsListViewHolder extends RecyclerView.ViewHolder {
TextView friendEmailText;
TextView friendRequestStatus;

FriendRequestsListViewHolder(View itemView) {
super(itemView);
friendEmailText = itemView.findViewById(R.id.text_friend_request_email);
friendRequestStatus = itemView.findViewById(R.id.text_friend_request_status);
}
}
}


61 changes: 61 additions & 0 deletions src/main/java/org/amahi/anywhere/adapter/FriendsListAdapter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package org.amahi.anywhere.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import org.amahi.anywhere.R;
import org.amahi.anywhere.server.model.FriendUserItem;

import java.util.List;

public class FriendsListAdapter extends RecyclerView.Adapter<FriendsListAdapter.FriendsListViewHolder> {
private List<FriendUserItem> friendsList;
private Context context;

public FriendsListAdapter(Context context, List<FriendUserItem> friendsList) {
this.context = context;
this.friendsList = friendsList;

}

@NonNull
@Override
public FriendsListViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return new FriendsListViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.friends_list_item, parent, false));
}

@Override
public void onBindViewHolder(@NonNull FriendsListViewHolder holder, int position) {
holder.friendEmailText.setText(friendsList.get(position).getEmail());
StringBuilder builder = new StringBuilder();
builder.append("Friends since ");
builder.append(friendsList.get(position).getCreatedAt());
holder.createdAt.setText(builder);

}

@Override
public int getItemCount() {
return friendsList.size();
}

class FriendsListViewHolder extends RecyclerView.ViewHolder {
TextView friendEmailText;
TextView createdAt;

FriendsListViewHolder(View itemView) {
super(itemView);
friendEmailText = itemView.findViewById(R.id.text_friend_email);
createdAt = itemView.findViewById(R.id.text_friend_created_at);

}
}
}


Loading