Skip to content

Commit

Permalink
Integrated Shares as a HeaderItem and its content as ListRowItem. Rem…
Browse files Browse the repository at this point in the history
…oved Apps(Permanently) and settings(temporary)

Moved the isATV() and Preferences code to the util/Preference.java

Implmented ViewStubs.

Fixed the ServerFileActivity crash in the android app.

Moved the isATV to a different class CheckAtv in the util package

Added the settings activity in the MainTVFragment

Implemented Sign-out, connection and sign-out preferences.

Removed fragment callback to improve structure.

Added network calls and made the TV independent of external fragment callbacks.

Added settings and separator.

Implemented the sort algorithm in the MainTVFragment
  • Loading branch information
octacode committed Jun 19, 2017
1 parent 6912e72 commit d00d3cf
Show file tree
Hide file tree
Showing 29 changed files with 818 additions and 314 deletions.
9 changes: 2 additions & 7 deletions src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,14 @@
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />

<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
</intent-filter>

<meta-data
android:name="android.max_aspect"
android:value="2.1" />
</activity>
<activity android:name=".activity.RedirectActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".activity.ServerAppActivity" />
<activity android:name=".activity.ServerFilesActivity">
<meta-data
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/amahi/anywhere/AmahiModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.amahi.anywhere.server.ApiModule;
import org.amahi.anywhere.service.AudioService;
import org.amahi.anywhere.service.VideoService;
import org.amahi.anywhere.tv.fragment.MainTVFragment;

import javax.inject.Singleton;

Expand Down Expand Up @@ -71,7 +72,8 @@
ServerFileDownloadingFragment.class,
SettingsFragment.class,
AudioService.class,
VideoService.class
VideoService.class,
MainTVFragment.class
}
)
class AmahiModule {
Expand Down
89 changes: 25 additions & 64 deletions src/main/java/org/amahi/anywhere/activity/NavigationActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

package org.amahi.anywhere.activity;

import android.app.UiModeManager;
import android.support.v4.app.Fragment;
import android.content.Intent;
import android.content.res.Configuration;
Expand All @@ -30,6 +29,7 @@
import android.view.Gravity;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewStub;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;

Expand All @@ -43,21 +43,16 @@
import org.amahi.anywhere.bus.SettingsSelectedEvent;
import org.amahi.anywhere.bus.ShareSelectedEvent;
import org.amahi.anywhere.bus.SharesSelectedEvent;
import org.amahi.anywhere.fragment.NavigationFragment;
import org.amahi.anywhere.fragment.ServerAppsFragment;
import org.amahi.anywhere.fragment.ServerSharesFragment;
import org.amahi.anywhere.server.client.ServerClient;
import org.amahi.anywhere.server.model.Server;
import org.amahi.anywhere.server.model.ServerApp;
import org.amahi.anywhere.server.model.ServerShare;
import org.amahi.anywhere.tv.activity.IntroActivity;
import org.amahi.anywhere.tv.activity.MainTVActivity;
import org.amahi.anywhere.util.Android;
import org.amahi.anywhere.util.CheckTV;
import org.amahi.anywhere.util.Fragments;
import org.amahi.anywhere.util.Intents;
import org.amahi.anywhere.util.Preferences;

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

import javax.inject.Inject;

Expand All @@ -68,10 +63,7 @@
* The navigation itself is done via {@link org.amahi.anywhere.fragment.NavigationFragment},
* {@link org.amahi.anywhere.fragment.ServerSharesFragment} and {@link org.amahi.anywhere.fragment.ServerAppsFragment}.
*/
public class NavigationActivity extends AppCompatActivity implements DrawerLayout.DrawerListener,
ServerAppsFragment.passAppsEvent,
ServerSharesFragment.passShareEvent,
NavigationFragment.passServerEvent
public class NavigationActivity extends AppCompatActivity implements DrawerLayout.DrawerListener
{
private static final class State
{
Expand All @@ -93,22 +85,36 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_navigation);

if(isATV()){
Boolean isFirstRun = getSharedPreferences("PREFERENCE", MODE_PRIVATE).getBoolean("isFirstRun", true);
if(CheckTV.isATV(this)){
Boolean isFirstRun = Preferences.getFirstRun(this);

if (isFirstRun) {
startActivity(new Intent(NavigationActivity.this, IntroActivity.class));
getSharedPreferences("PREFERENCE", MODE_PRIVATE).edit().putBoolean("isFirstRun", false).apply();
Preferences.setFirstRun(this);
}

ViewStub stub = (ViewStub) findViewById(R.id.view_stub_container_files_dummy);
stub.inflate();

ViewStub viewStub = (ViewStub) findViewById(R.id.view_stub_tv_loading);
viewStub.inflate();

FrameLayout containerContent = (FrameLayout)findViewById(R.id.container_content);

FrameLayout containerNavigation = (FrameLayout)findViewById(R.id.container_navigation);

RelativeLayout tvLoading = (RelativeLayout)findViewById(R.id.tv_loading);

containerContent.setVisibility(View.INVISIBLE);

containerNavigation.setVisibility(View.INVISIBLE);

tvLoading.setVisibility(View.VISIBLE);

getSupportActionBar().hide();

setUpNavigationFragment();
Fragments.Operator.at(this).replace(buildAppsFragment(), R.id.container_apps_dummy);

setUpShares();
}

Expand Down Expand Up @@ -138,7 +144,7 @@ private void setUpNavigation(Bundle state) {
setUpNavigationDrawer();
}

if(!isATV())setUpNavigationFragment();
if(!CheckTV.isATV(this))setUpNavigationFragment();

if (isNavigationDrawerAvailable() && isNavigationDrawerRequired(state)) {
showNavigationDrawer();
Expand Down Expand Up @@ -225,7 +231,7 @@ private boolean isNavigationDrawerRequired(Bundle state) {
}

private void showNavigationDrawer() {
if(!isATV())
if(!CheckTV.isATV(this))
getDrawer().openDrawer(findViewById(R.id.container_navigation));
}

Expand Down Expand Up @@ -369,49 +375,4 @@ protected void onPause() {

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

protected boolean isATV() {
UiModeManager uiModeManager = (UiModeManager) getSystemService(UI_MODE_SERVICE);
return (uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION);
}

@Override
public void passShare(List<ServerShare> serverShares) {
if(isATV()){

Intent tvIntent = new Intent(this,MainTVActivity.class);


if(serverApps!=null){
ArrayList<ServerApp> serverAppsArrayList = new ArrayList<>(serverApps);
tvIntent.putParcelableArrayListExtra(getString(R.string.intent_apps),serverAppsArrayList);
}

if(serverShares!=null) {
ArrayList<ServerShare> serverShareArrayList = new ArrayList<>(serverShares);
tvIntent.putParcelableArrayListExtra(getString(R.string.intent_shares),serverShareArrayList);
}

if(servers!=null){
ArrayList<Server> serverArrayList = new ArrayList<>(servers);
tvIntent.putParcelableArrayListExtra(getString(R.string.intent_servers),serverArrayList);
}
startActivity(tvIntent);
}
}

List<ServerApp> serverApps;
List<Server> servers;

@Override
public void passApps(List<ServerApp> serverApps) {
if(isATV())
this.serverApps = serverApps;
}

@Override
public void passServer(List<Server> serverList) {
if(isATV())
servers = serverList;
}
}
}
17 changes: 0 additions & 17 deletions src/main/java/org/amahi/anywhere/activity/RedirectActivity.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.amahi.anywhere.bus.ServerFileSharingEvent;
import org.amahi.anywhere.fragment.ServerFileDownloadingFragment;
import org.amahi.anywhere.fragment.GooglePlaySearchFragment;
import org.amahi.anywhere.fragment.ServerFilesFragment;
import org.amahi.anywhere.server.client.ServerClient;
import org.amahi.anywhere.server.model.ServerFile;
import org.amahi.anywhere.server.model.ServerShare;
Expand Down
29 changes: 8 additions & 21 deletions src/main/java/org/amahi/anywhere/fragment/NavigationFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import android.accounts.AuthenticatorException;
import android.accounts.OnAccountsUpdateListener;
import android.accounts.OperationCanceledException;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.Fragment;
import android.content.SharedPreferences;
import android.os.Bundle;
Expand All @@ -35,7 +35,6 @@
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
Expand Down Expand Up @@ -63,6 +62,8 @@
import org.amahi.anywhere.server.client.AmahiClient;
import org.amahi.anywhere.server.client.ServerClient;
import org.amahi.anywhere.server.model.Server;
import org.amahi.anywhere.tv.activity.MainTVActivity;
import org.amahi.anywhere.util.CheckTV;
import org.amahi.anywhere.util.RecyclerItemClickListener;
import org.amahi.anywhere.util.ViewDirector;

Expand All @@ -89,12 +90,6 @@ private State() {
public static final String SERVERS = "servers";
}

public interface passServerEvent{
void passServer(List<Server> serverList);
}

private passServerEvent passServerEventListener;

@Inject
AmahiClient amahiClient;

Expand Down Expand Up @@ -283,24 +278,12 @@ private void setUpServersContent(String authenticationToken) {
amahiClient.getServers(authenticationToken);
}

@Override
public void onAttach(Context context) {
super.onAttach(context);
try {
passServerEventListener = (passServerEvent)context;
} catch (ClassCastException e) {
throw new ClassCastException(context.toString() + " must implement passServerEventListener");
}
}

@Subscribe
public void onServersLoaded(ServersLoadedEvent event) {
setUpServersContent(event.getServers());

//FRAGMENT CALLBACK
passServerEventListener.passServer(filterActiveServers(event.getServers()));

setUpNavigation();

showContent();
}

Expand Down Expand Up @@ -397,6 +380,7 @@ public void onServerConnected(ServerConnectedEvent event) {
private void setUpServerConnection() {
if (!isConnectionAvailable() || isConnectionAuto()) {
serverClient.connectAuto();
if(CheckTV.isATV(getContext()))launchTV();
return;
}

Expand All @@ -405,8 +389,11 @@ private void setUpServerConnection() {
} else {
serverClient.connectRemote();
}
if(CheckTV.isATV(getContext()))launchTV();
}

private void launchTV(){startActivity(new Intent(getContext(),MainTVActivity.class));}

private boolean isConnectionAvailable() {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getActivity());

Expand Down
18 changes: 0 additions & 18 deletions src/main/java/org/amahi/anywhere/fragment/ServerAppsFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@ private State() {
public static final String APPS = "apps";
}

public interface passAppsEvent{
void passApps(List<ServerApp> serverApps);
}

private ServerAppsAdapter mServerAppsAdapter;

private RecyclerView mRecyclerView;
Expand All @@ -74,7 +70,6 @@ public interface passAppsEvent{

private LinearLayout mErrorLinearLayout;

private passAppsEvent passAppsEventListener;
@Inject
ServerClient serverClient;

Expand Down Expand Up @@ -163,16 +158,6 @@ private void setUpAppsContent() {
}
}

@Override
public void onAttach(Context context) {
super.onAttach(context);
try {
passAppsEventListener = (passAppsEvent) context;
} catch (ClassCastException e) {
throw new ClassCastException(context.toString() + " must implement passAppsEventListener");
}
}

@Subscribe
public void onServerConnectionChanged(ServerConnectionChangedEvent event) {
serverClient.getApps();
Expand All @@ -182,9 +167,6 @@ public void onServerConnectionChanged(ServerConnectionChangedEvent event) {
public void onAppsLoaded(ServerAppsLoadedEvent event) {
setUpAppsContent(event.getServerApps());

//FRAGMENT CALLBACK
passAppsEventListener.passApps(event.getServerApps());

showAppsContent();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@

import android.Manifest;
import android.app.SearchManager;
import android.app.UiModeManager;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
Expand Down Expand Up @@ -76,6 +78,7 @@

import javax.inject.Inject;

import static android.content.Context.UI_MODE_SERVICE;
import static android.support.v4.content.PermissionChecker.checkSelfPermission;

/**
Expand Down
Loading

0 comments on commit d00d3cf

Please sign in to comment.