Skip to content

Commit 1755619

Browse files
committed
NavigationDrawer sections completed:
- Films, Locations, Characters - TODO: put images in App resources or get from server
1 parent c0b8fef commit 1755619

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+2450
-314
lines changed

CREDITS.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ By Source, Fair use, https://en.wikipedia.org/w/index.php?curid=48614572
5858
when_marnie_was_there
5959
By Source (WP:NFCC#4), Fair use, https://en.wikipedia.org/w/index.php?curid=41687257
6060

61-
62-
63-
61+
logo_studio_ghibli
62+
By Source, Fair use, https://en.wikipedia.org/wiki/Studio_Ghibli#/media/File:Studio_Ghibli_logo.svg
6463

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ android {
77
applicationId "org.app.txema.ghiblifilms"
88
minSdkVersion 15
99
targetSdkVersion 25
10-
versionCode 4
11-
versionName "1.0.4"
10+
versionCode 5
11+
versionName "1.0.5"
1212
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
1313
}
1414
buildTypes {

app/src/main/java/org/app/txema/ghiblifilms/MainActivity.java

Lines changed: 193 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,56 @@
22

33
import android.content.Intent;
44
import android.content.pm.ActivityInfo;
5-
import android.content.res.Resources;
65
import android.net.Uri;
76
import android.os.Bundle;
87
import android.support.design.widget.AppBarLayout;
98
import android.support.design.widget.CollapsingToolbarLayout;
109
import android.support.v4.app.DialogFragment;
10+
import android.support.v4.widget.DrawerLayout;
1111
import android.support.v7.app.AppCompatActivity;
1212
import android.support.v7.widget.Toolbar;
1313
import android.util.Log;
1414
import android.view.Menu;
1515
import android.view.MenuItem;
16+
import android.view.View;
1617
import android.widget.ImageView;
17-
import android.widget.Toast;
18+
import android.widget.ProgressBar;
1819

1920
import com.bumptech.glide.Glide;
2021
import com.google.android.gms.ads.AdListener;
21-
import com.google.android.gms.ads.AdRequest;
2222
import com.google.android.gms.ads.AdView;
2323

2424
import org.app.txema.ghiblifilms.di.App;
25+
import org.app.txema.ghiblifilms.model.NavDrawerItem;
2526
import org.app.txema.ghiblifilms.view.fragment.AboutUsFragment;
27+
import org.app.txema.ghiblifilms.view.fragment.CharacterDetailsFragment;
28+
import org.app.txema.ghiblifilms.view.fragment.CharacterListFragment;
29+
import org.app.txema.ghiblifilms.view.fragment.FilmDetailsFragment;
30+
import org.app.txema.ghiblifilms.view.fragment.FilmListFragment;
31+
import org.app.txema.ghiblifilms.view.fragment.LocationDetailsFragment;
32+
import org.app.txema.ghiblifilms.view.fragment.LocationListFragment;
33+
import org.app.txema.ghiblifilms.view.fragment.NavigationDrawerFragment;
2634

27-
public class MainActivity extends AppCompatActivity {
28-
private static final String TAG = MainActivity.class.getSimpleName();
35+
import static org.app.txema.ghiblifilms.view.util.Tag.TAG_DETAILS_FRAGMENT;
36+
import static org.app.txema.ghiblifilms.view.util.Tag.TAG_LIST_FRAGMENT;
2937

30-
private AdView mAdView;
38+
public class MainActivity extends AppCompatActivity implements NavigationDrawerFragment.FragmentDrawerListener {
3139

40+
private AdView mAdView;
41+
protected ProgressBar progressBar;
3242

3343
@Override
3444
protected void onCreate(Bundle savedInstanceState) {
3545
super.onCreate(savedInstanceState);
3646
setContentView(R.layout.activity_main);
3747

38-
//AdMobs
39-
mAdView = (AdView) findViewById(R.id.adView);
40-
AdRequest adRequest = new AdRequest.Builder().build();
41-
mAdView.loadAd(adRequest);
42-
adMobListener();
48+
progressBar = (ProgressBar)findViewById(R.id.progressBar);
49+
50+
//AdMobs TODO
51+
//mAdView = (AdView) findViewById(R.id.adView);
52+
//AdRequest adRequest = new AdRequest.Builder().build();
53+
//mAdView.loadAd(adRequest);
54+
//adMobListener();
4355

4456
//DI with Dagger
4557
((App) getApplication()).getAppComponent().inject(this);
@@ -56,14 +68,183 @@ protected void onCreate(Bundle savedInstanceState) {
5668
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
5769
setSupportActionBar(toolbar);
5870

71+
//NavigationDrawerFragment declaration
72+
NavigationDrawerFragment navDrawerFragment = (NavigationDrawerFragment)
73+
getSupportFragmentManager().findFragmentById(R.id.fragment_navigation_drawer);
74+
navDrawerFragment.setUp(R.id.fragment_navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout), toolbar);
75+
navDrawerFragment.setDrawerListener(this);
76+
5977
//Set image cover for collapsingLayout (Using Glide)
6078
try {
61-
Glide.with(this).load(R.drawable.cover).into((ImageView) findViewById(R.id.backdrop));
79+
Glide.with(this).load(R.drawable.cover).centerCrop().into((ImageView)findViewById(R.id.backdrop));
6280
} catch (Exception e) {
6381
e.printStackTrace();
6482
}
6583

6684
setScreenOrientation();
85+
86+
//insert fragment at right pane if layout is two panes
87+
if (getResources().getBoolean(R.bool.two_panes)) {
88+
insertDefaultDetailsFragment();
89+
}
90+
91+
//insert fragment list
92+
insertFilmListFragment();
93+
}
94+
95+
@Override
96+
public boolean onCreateOptionsMenu(Menu menu) {
97+
// Inflate the menu; this adds items to the action bar if it is present.
98+
getMenuInflater().inflate(R.menu.menu_main, menu);
99+
return true;
100+
}
101+
102+
@Override
103+
public boolean onOptionsItemSelected(MenuItem item) {
104+
// Handle action bar item clicks.
105+
int id = item.getItemId();
106+
107+
//noinspection SimplifiableIfStatement
108+
if (id == R.id.action_about_us) {
109+
DialogFragment newFragment = new AboutUsFragment();
110+
newFragment.show(getSupportFragmentManager(), DialogFragment.class.getSimpleName());
111+
return true;
112+
}
113+
114+
if (id == R.id.action_rate_app) {
115+
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=org.app.txema.ghiblifilms"));
116+
startActivity(browserIntent);
117+
}
118+
119+
return super.onOptionsItemSelected(item);
120+
}
121+
122+
private void setScreenOrientation() {
123+
if (getResources().getBoolean(R.bool.two_panes)) {
124+
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
125+
} else {
126+
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
127+
}
128+
}
129+
130+
@Override
131+
public void onDrawerItemSelected(View view, int position) {
132+
if (position != NavDrawerItem.SELECTED) {
133+
switch (position) {
134+
case NavDrawerItem.FILMS:
135+
if (getResources().getBoolean(R.bool.two_panes)) {
136+
insertFilmDetailsFragment();
137+
}
138+
insertFilmListFragment();
139+
break;
140+
case NavDrawerItem.CHARACTERS:
141+
if (getResources().getBoolean(R.bool.two_panes)) {
142+
insertCharacterDetailsFragment();
143+
}
144+
insertCharacterListFragment();
145+
break;
146+
case NavDrawerItem.LOCATIONS:
147+
if (getResources().getBoolean(R.bool.two_panes)) {
148+
insertLocationDetailsFragment();
149+
}
150+
insertLocationsListFragment();
151+
break;
152+
}
153+
NavDrawerItem.SELECTED = position;
154+
}
155+
}
156+
157+
// *****************************************
158+
// FRAGMENTS TO INSERT: 1) DetailsFragment
159+
// *****************************************
160+
161+
//default details fragment
162+
private void insertDefaultDetailsFragment() {
163+
// Create a new Fragment to be placed in the activity layout
164+
FilmDetailsFragment fragment = new FilmDetailsFragment();
165+
166+
// Add the fragment to the 'fragment_details' FrameLayout
167+
getSupportFragmentManager().beginTransaction()
168+
.add(R.id.details_fragment, fragment, TAG_DETAILS_FRAGMENT)
169+
.addToBackStack(null)
170+
.commit();
171+
}
172+
173+
//film details fragment
174+
private void insertFilmDetailsFragment() {
175+
// Create a new Fragment to be placed in the activity layout
176+
FilmDetailsFragment fragment = new FilmDetailsFragment();
177+
178+
// Replace the fragment to the 'fragment_details' FrameLayout
179+
getSupportFragmentManager().beginTransaction()
180+
.replace(R.id.details_fragment, fragment, TAG_DETAILS_FRAGMENT)
181+
.commit();
182+
183+
}
184+
185+
//character details fragment
186+
private void insertCharacterDetailsFragment() {
187+
// Create a new Fragment to be placed in the activity layout
188+
CharacterDetailsFragment fragment = new CharacterDetailsFragment();
189+
190+
// Replace the fragment to the 'fragment_details' FrameLayout
191+
getSupportFragmentManager().beginTransaction()
192+
.replace(R.id.details_fragment, fragment, TAG_DETAILS_FRAGMENT)
193+
.commit();
194+
}
195+
196+
//locations details fragment
197+
private void insertLocationDetailsFragment() {
198+
// Create a new Fragment to be placed in the activity layout
199+
LocationDetailsFragment fragment = new LocationDetailsFragment();
200+
201+
// Replace the fragment to the 'fragment_details' FrameLayout
202+
getSupportFragmentManager().beginTransaction()
203+
.replace(R.id.details_fragment, fragment, TAG_DETAILS_FRAGMENT)
204+
.commit();
205+
}
206+
207+
// *****************************************
208+
// FRAGMENTS TO INSERT: 2) ListFragment
209+
// *****************************************
210+
211+
//films list fragment
212+
private void insertFilmListFragment() {
213+
// Create a new Fragment to be placed in the activity layout
214+
FilmListFragment fragment = new FilmListFragment();
215+
216+
// Add the fragment to the 'fragment_list' FrameLayout
217+
getSupportFragmentManager().beginTransaction()
218+
.add(R.id.list_fragment, fragment, TAG_LIST_FRAGMENT)
219+
.commit();
220+
}
221+
222+
//characters list fragment
223+
private void insertCharacterListFragment() {
224+
// Create a new Fragment to be placed in the activity layout
225+
CharacterListFragment fragment = new CharacterListFragment();
226+
227+
// Add the fragment to the 'fragment_list' FrameLayout
228+
getSupportFragmentManager().beginTransaction()
229+
.replace(R.id.list_fragment, fragment, TAG_LIST_FRAGMENT).commit();
230+
}
231+
232+
//locations list fragment
233+
private void insertLocationsListFragment() {
234+
// Create a new Fragment to be placed in the activity layout
235+
LocationListFragment fragment = new LocationListFragment();
236+
237+
// Add the fragment to the 'fragment_list' FrameLayout
238+
getSupportFragmentManager().beginTransaction()
239+
.replace(R.id.list_fragment, fragment, TAG_LIST_FRAGMENT).commit();
240+
}
241+
242+
public void showProgress() {
243+
progressBar.setVisibility(View.VISIBLE);
244+
}
245+
246+
public void hideProgress() {
247+
progressBar.setVisibility(View.GONE);
67248
}
68249

69250
private void adMobListener() {
@@ -101,43 +282,4 @@ public void onAdClosed() {
101282
}
102283
});
103284
}
104-
105-
@Override
106-
public boolean onCreateOptionsMenu(Menu menu) {
107-
// Inflate the menu; this adds items to the action bar if it is present.
108-
getMenuInflater().inflate(R.menu.menu_main, menu);
109-
return true;
110-
}
111-
112-
@Override
113-
public boolean onOptionsItemSelected(MenuItem item) {
114-
// Handle action bar item clicks here. The action bar will
115-
// automatically handle clicks on the Home/Up button, so long
116-
// as you specify a parent activity in AndroidManifest.xml.
117-
int id = item.getItemId();
118-
119-
//noinspection SimplifiableIfStatement
120-
if (id == R.id.action_about_us) {
121-
DialogFragment newFragment = new AboutUsFragment();
122-
newFragment.show(getSupportFragmentManager(), "aboutUs");
123-
return true;
124-
}
125-
126-
if (id == R.id.action_rate_app) {
127-
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=org.app.txema.ghiblifilms"));
128-
startActivity(browserIntent);
129-
}
130-
131-
return super.onOptionsItemSelected(item);
132-
}
133-
134-
private void setScreenOrientation() {
135-
Resources res = getResources();
136-
boolean twoPanes = res.getBoolean(R.bool.two_panes);
137-
if(twoPanes) {
138-
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
139-
} else {
140-
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
141-
}
142-
}
143285
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package org.app.txema.ghiblifilms.contract;
2+
3+
import org.app.txema.ghiblifilms.model.Character;
4+
5+
import java.util.List;
6+
7+
/**
8+
* Created by Txema on 17/09/2017.
9+
*/
10+
11+
public interface CharacterContract {
12+
13+
interface View {
14+
void onDataStarted();
15+
void onDataCompleted();
16+
void showData(List<Character> characters);
17+
void onDataError(Throwable e);
18+
}
19+
20+
interface Presenter {
21+
void loadData();
22+
void onStop();
23+
}
24+
}

app/src/main/java/org/app/txema/ghiblifilms/presenter/MainContract.java renamed to app/src/main/java/org/app/txema/ghiblifilms/contract/FilmContract.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.app.txema.ghiblifilms.presenter;
1+
package org.app.txema.ghiblifilms.contract;
22

33
import org.app.txema.ghiblifilms.model.Film;
44

@@ -8,7 +8,7 @@
88
* Created by Txema on 17/09/2017.
99
*/
1010

11-
public interface MainContract {
11+
public interface FilmContract {
1212

1313
interface View {
1414
void onDataStarted();
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package org.app.txema.ghiblifilms.contract;
2+
3+
import org.app.txema.ghiblifilms.model.Location;
4+
5+
import java.util.List;
6+
7+
/**
8+
* Created by Txema on 17/09/2017.
9+
*/
10+
11+
public interface LocationContract {
12+
13+
interface View {
14+
void onDataStarted();
15+
void onDataCompleted();
16+
void showData(List<Location> characters);
17+
void onDataError(Throwable e);
18+
}
19+
20+
interface Presenter {
21+
void loadData();
22+
void onStop();
23+
}
24+
}

0 commit comments

Comments
 (0)