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

Beta friendship feature #523

Open
wants to merge 2 commits into
base: beta
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ static def formatStringField(field) {
}

dependencies {
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
repositories {
google()
mavenCentral()
Expand Down Expand Up @@ -170,6 +172,7 @@ dependencies {
implementation 'android.arch.persistence.room:runtime:' + rootProject.archRoomVersion
annotationProcessor 'android.arch.persistence.room:compiler:' + rootProject.archRoomVersion

implementation 'com.balysv:material-ripple:1.0.2' // ripple effect
// Uncomment the dependencies below to enable Chuck Interceptor for logging
/*
debugImplementation 'com.readystatesoftware.chuck:library:1.1.0'
Expand Down
28 changes: 7 additions & 21 deletions src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,23 +1,6 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright (c) 2014 Amahi
~
~ This file is part of Amahi.
~
~ Amahi 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.
~
~ Amahi 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 Amahi. If not, see <http ://www.gnu.org/licenses/>.
-->
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:tools="http://schemas.android.com/tools"
package="org.amahi.anywhere"
android:installLocation="auto">

Expand All @@ -32,7 +15,7 @@
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />

<permission android:name="android.permission.MEDIA_CONTENT_CONTROL" />

Expand All @@ -56,6 +39,9 @@
android:theme="@style/Theme.Amahi"
android:usesCleartextTraffic="true"
tools:ignore="GoogleAppIndexingWarning">
<activity android:name=".activity.FriendsActivity"
android:theme="@style/Theme.Amahi.Friends" ></activity>

<provider
android:name="androidx.core.content.FileProvider"
android:authorities="org.amahi.anywhere.fileprovider"
Expand Down Expand Up @@ -222,7 +208,7 @@
android:value="org.amahi.anywhere.util.CastOptionsProvider" />

<activity android:name=".activity.OfflineFilesActivity" />
<activity android:name=".activity.RecentFilesActivity"></activity>
<activity android:name=".activity.RecentFilesActivity" />
</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 @@ -76,6 +79,7 @@
injects = {
AuthenticationActivity.class,
NavigationActivity.class,
FriendsActivity.class,
ServerAppActivity.class,
OfflineFilesActivity.class,
ServerFilesActivity.class,
Expand Down Expand Up @@ -107,7 +111,9 @@
TvPlaybackVideoActivity.class,
TvPlaybackAudioActivity.class,
TvPlaybackAudioFragment.class,
AudioMetadataRetrievingTask.class
AudioMetadataRetrievingTask.class,
FriendsFragment.class,
FriendRequestsFragment.class
}
)
class AmahiModule {
Expand Down
195 changes: 195 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,195 @@
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 android.widget.Toast;

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.bus.FriendRequestsLoadedEvent;
import org.amahi.anywhere.bus.FriendUsersLoadedEvent;
import org.amahi.anywhere.fragment.FriendRequestsFragment;
import org.amahi.anywhere.fragment.FriendsFragment;
import org.amahi.anywhere.server.api.ServerApi;
import org.amahi.anywhere.server.client.ServerClient;
import org.amahi.anywhere.server.model.FriendRequestResponse;
import org.amahi.anywhere.server.model.FriendUserResponse;

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

import javax.inject.Inject;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

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());

loadData();
}

private void loadData() {

Retrofit friendUsers = new Retrofit.Builder()
.baseUrl("https://friending-testing.herokuapp.com/")
.addConverterFactory(GsonConverterFactory.create())
.build();

ServerApi frndUserserverApi = friendUsers.create(ServerApi.class);

Call<FriendUserResponse> frndUsercall = frndUserserverApi.getFriendUsers("abcdef");


frndUsercall.enqueue(new Callback<FriendUserResponse>() {
@Override
public void onResponse(Call<FriendUserResponse> call, Response<FriendUserResponse> response) {
if(!response.isSuccessful()){
Toast.makeText(FriendsActivity.this, "fail", Toast.LENGTH_SHORT).show();
return;
}
FriendUserResponse friendUserResponse = response.body();
BusProvider.getBus().post(new FriendUsersLoadedEvent(friendUserResponse.getFriendUsers()));
}

@Override
public void onFailure(Call<FriendUserResponse> call, Throwable t) {

}
});



Retrofit friendRequests = new Retrofit.Builder()
.baseUrl("https://friending-testing.herokuapp.com/")
.addConverterFactory(GsonConverterFactory.create())
.build();

ServerApi frndRequestServerapi = friendRequests.create(ServerApi.class);

Call<FriendRequestResponse> frndRequestcall = frndRequestServerapi.getFriendRequests("abcdef");


frndRequestcall.enqueue(new Callback<FriendRequestResponse>() {
@Override
public void onResponse(Call<FriendRequestResponse> call, Response<FriendRequestResponse> response) {
if(!response.isSuccessful()){
Toast.makeText(FriendsActivity.this, "fail", Toast.LENGTH_SHORT).show();
return;
}

FriendRequestResponse friendRequestResponse = response.body();
BusProvider.getBus().post(new FriendRequestsLoadedEvent(friendRequestResponse.getFriendRequests()));
}

@Override
public void onFailure(Call<FriendRequestResponse> call, Throwable t) {

}
});

}

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);
}

}
Loading