Browse Source

v0.2

Replaced menu with NavigationDrawer
Replaced TopicActivity's Actionbar with Toolbar
pull/24/head
Ezerous 8 years ago
parent
commit
60f441d453
  1. 5
      app/build.gradle
  2. 5
      app/src/main/AndroidManifest.xml
  3. 130
      app/src/main/java/gr/thmmy/mthmmy/activities/BaseActivity.java
  4. 99
      app/src/main/java/gr/thmmy/mthmmy/activities/MainActivity.java
  5. 17
      app/src/main/java/gr/thmmy/mthmmy/activities/TopicActivity.java
  6. 2
      app/src/main/java/gr/thmmy/mthmmy/data/Post.java
  7. 18
      app/src/main/res/layout/activity_topic.xml
  8. 22
      app/src/main/res/menu/menu_main.xml

5
app/build.gradle

@ -9,8 +9,8 @@ android {
applicationId "gr.thmmy.mthmmy" applicationId "gr.thmmy.mthmmy"
minSdkVersion 19 minSdkVersion 19
targetSdkVersion 25 targetSdkVersion 25
versionCode 3 versionCode 4
versionName "0.17" versionName "0.2"
} }
buildTypes { buildTypes {
release { release {
@ -35,4 +35,5 @@ dependencies {
compile('com.mikepenz:materialdrawer:5.7.0@aar') { compile('com.mikepenz:materialdrawer:5.7.0@aar') {
transitive = true transitive = true
} }
compile 'com.mikepenz:fontawesome-typeface:4.7.0.0@aar'
} }

5
app/src/main/AndroidManifest.xml

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="gr.thmmy.mthmmy"> package="gr.thmmy.mthmmy">
<uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
@ -40,7 +40,8 @@
<activity <activity
android:name=".activities.TopicActivity" android:name=".activities.TopicActivity"
android:configChanges="orientation|screenSize" android:configChanges="orientation|screenSize"
android:parentActivityName=".activities.MainActivity"> android:parentActivityName=".activities.MainActivity"
android:theme="@style/AppTheme.NoActionBar">
<meta-data <meta-data
android:name="android.support.PARENT_ACTIVITY" android:name="android.support.PARENT_ACTIVITY"
android:value=".activities.MainActivity"/> android:value=".activities.MainActivity"/>

130
app/src/main/java/gr/thmmy/mthmmy/activities/BaseActivity.java

@ -1,16 +1,32 @@
package gr.thmmy.mthmmy.activities; package gr.thmmy.mthmmy.activities;
import android.app.ProgressDialog;
import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Toast;
import com.franmontiel.persistentcookiejar.PersistentCookieJar; import com.franmontiel.persistentcookiejar.PersistentCookieJar;
import com.franmontiel.persistentcookiejar.cache.SetCookieCache; import com.franmontiel.persistentcookiejar.cache.SetCookieCache;
import com.franmontiel.persistentcookiejar.persistence.SharedPrefsCookiePersistor; import com.franmontiel.persistentcookiejar.persistence.SharedPrefsCookiePersistor;
import com.mikepenz.fontawesome_typeface_library.FontAwesome;
import com.mikepenz.iconics.IconicsDrawable;
import com.mikepenz.materialdrawer.Drawer;
import com.mikepenz.materialdrawer.DrawerBuilder;
import com.mikepenz.materialdrawer.model.PrimaryDrawerItem;
import com.mikepenz.materialdrawer.model.interfaces.IDrawerItem;
import gr.thmmy.mthmmy.R;
import gr.thmmy.mthmmy.session.SessionManager; import gr.thmmy.mthmmy.session.SessionManager;
import okhttp3.OkHttpClient; import okhttp3.OkHttpClient;
import static gr.thmmy.mthmmy.session.SessionManager.LOGGED_IN;
public class BaseActivity extends AppCompatActivity public class BaseActivity extends AppCompatActivity
{ {
// Client & Cookies // Client & Cookies
@ -28,6 +44,9 @@ public class BaseActivity extends AppCompatActivity
//Other variables //Other variables
private static boolean init = false; //To initialize stuff only once per app start private static boolean init = false; //To initialize stuff only once per app start
//Common UI elements
protected Toolbar toolbar;
protected Drawer drawer;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -51,4 +70,115 @@ public class BaseActivity extends AppCompatActivity
return client; return client;
} }
//TODO: move stuff below
//------------------------------------------DRAWER STUFF----------------------------------------
private static final int LOGINLOGOUT_ID=0;
private static final int ABOUT_ID=1;
protected PrimaryDrawerItem loginLogout, about;
protected IconicsDrawable loginIcon,logoutIcon, aboutIcon;
/**
* Call only after initializing Toolbar
*/
protected void createDrawer()//TODO
{
loginIcon =new IconicsDrawable(this)
.icon(FontAwesome.Icon.faw_sign_in)
.color(Color.BLACK)
.sizeDp(24);
logoutIcon =new IconicsDrawable(this)
.icon(FontAwesome.Icon.faw_sign_out)
.color(Color.BLACK)
.sizeDp(24);
loginLogout = new PrimaryDrawerItem().withIdentifier(LOGINLOGOUT_ID).withName(R.string.logout).withIcon(logoutIcon);
aboutIcon =new IconicsDrawable(this)
.icon(FontAwesome.Icon.faw_info_circle)
.color(Color.BLACK)
.sizeDp(24);
about = new PrimaryDrawerItem().withIdentifier(ABOUT_ID).withName(R.string.about).withIcon(aboutIcon);
drawer = new DrawerBuilder().withActivity(BaseActivity.this)
.withToolbar(toolbar)
.addDrawerItems(loginLogout,about)
.withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
@Override
public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
if(drawerItem.equals(LOGINLOGOUT_ID))
{
if (sessionManager.getLogStatus()!= LOGGED_IN) //When logged out or if user is guest
{
Intent intent = new Intent(BaseActivity.this, LoginActivity.class);
startActivity(intent);
finish();
overridePendingTransition(R.anim.push_right_in, R.anim.push_right_out);
}
else
new LogoutTask().execute();
}
else if(drawerItem.equals(ABOUT_ID))
{
Intent i = new Intent(BaseActivity.this, AboutActivity.class);
startActivity(i);
}
drawer.closeDrawer();
return true;
}
})
.build();
drawer.setSelection(-1);
}
protected void updateDrawer()
{
if(drawer!=null)
{
if (sessionManager.getLogStatus()!= LOGGED_IN) //When logged out or if user is guest
{
//Swap logout with login
loginLogout.withName(R.string.login).withIcon(loginIcon);
drawer.updateItem(loginLogout);
}
else
{
//Swap login with logout
loginLogout.withName(R.string.logout).withIcon(logoutIcon);
drawer.updateItem(loginLogout);
}
}
}
//-------------------------------------------LOGOUT-------------------------------------------------
/**
* Result toast will always display a success, because when user chooses logout all data are
* cleared regardless of the actual outcome
*/
protected class LogoutTask extends AsyncTask<Void, Void, Integer> { //Attempt logout
ProgressDialog progressDialog;
protected Integer doInBackground(Void... voids) {
return sessionManager.logout();
}
protected void onPreExecute()
{ //Show a progress dialog until done
progressDialog = new ProgressDialog(BaseActivity.this,
R.style.AppTheme_Dark_Dialog);
progressDialog.setCancelable(false);
progressDialog.setIndeterminate(true);
progressDialog.setMessage("Logging out...");
progressDialog.show();
}
protected void onPostExecute(Integer result)
{
Toast.makeText(getBaseContext(), "Logged out successfully!", Toast.LENGTH_LONG).show();
updateDrawer();
progressDialog.dismiss();
}
}
//-----------------------------------------LOGOUT END-----------------------------------------------
} }

99
app/src/main/java/gr/thmmy/mthmmy/activities/MainActivity.java

@ -1,8 +1,6 @@
package gr.thmmy.mthmmy.activities; package gr.thmmy.mthmmy.activities;
import android.app.ProgressDialog;
import android.content.Intent; import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.support.design.widget.TabLayout; import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
@ -10,23 +8,18 @@ import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager; import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;
import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.R;
import gr.thmmy.mthmmy.data.TopicSummary; import gr.thmmy.mthmmy.data.TopicSummary;
import gr.thmmy.mthmmy.sections.forum.ForumFragment; import gr.thmmy.mthmmy.sections.forum.ForumFragment;
import gr.thmmy.mthmmy.sections.recent.RecentFragment; import gr.thmmy.mthmmy.sections.recent.RecentFragment;
import static gr.thmmy.mthmmy.session.SessionManager.LOGGED_IN;
import static gr.thmmy.mthmmy.session.SessionManager.LOGGED_OUT; import static gr.thmmy.mthmmy.session.SessionManager.LOGGED_OUT;
public class MainActivity extends BaseActivity implements RecentFragment.OnListFragmentInteractionListener, ForumFragment.OnListFragmentInteractionListener { public class MainActivity extends BaseActivity implements RecentFragment.OnListFragmentInteractionListener, ForumFragment.OnListFragmentInteractionListener {
//----------------------------------------CLASS VARIABLES----------------------------------------- //----------------------------------------CLASS VARIABLES-----------------------------------------
private static final String TAG = "MainActivity"; private static final String TAG = "MainActivity";
private Menu menu;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -42,9 +35,12 @@ public class MainActivity extends BaseActivity implements RecentFragment.OnListF
} }
//Initialize toolbar //Initialize toolbar
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
//Initialize drawer
createDrawer();
//Create the adapter that will return a fragment for each section of the activity //Create the adapter that will return a fragment for each section of the activity
SectionsPagerAdapter mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); SectionsPagerAdapter mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
@ -54,66 +50,17 @@ public class MainActivity extends BaseActivity implements RecentFragment.OnListF
TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs); TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
tabLayout.setupWithViewPager(mViewPager); tabLayout.setupWithViewPager(mViewPager);
//TODO: Drawer
// new DrawerBuilder().withActivity(this)
// .withToolbar(toolbar)
// .build();
} }
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { protected void onResume() {
//Inflate the menu; this adds items to the action bar if it is present. super.onResume();
this.menu = menu; updateDrawer();
getMenuInflater().inflate(R.menu.menu_main, menu);
if (sessionManager.getLogStatus()!= LOGGED_IN) //When logged out or if user is guest
hideLogout();
else
hideLogin();
return true;
} }
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_about) {
//Go to about
Intent i = new Intent(MainActivity.this, AboutActivity.class);
startActivity(i);
return true;
} else if (id == R.id.action_logout)
//Attempt logout
new LogoutTask().execute();
else {
//Go to login
Intent intent = new Intent(MainActivity.this, LoginActivity.class);
startActivity(intent);
finish();
overridePendingTransition(R.anim.push_right_in, R.anim.push_right_out);
}
return super.onOptionsItemSelected(item);
}
private void hideLogin() { //Hide login AND show logout
MenuItem login = menu.findItem(R.id.action_login);
MenuItem logout = menu.findItem(R.id.action_logout);
login.setVisible(false);
logout.setVisible(true);
}
private void hideLogout() { //Hide logout AND show login
MenuItem login = menu.findItem(R.id.action_login);
MenuItem logout = menu.findItem(R.id.action_logout);
login.setVisible(true);
logout.setVisible(false);
}
@Override @Override
public void onFragmentInteraction(TopicSummary topicSummary) { public void onFragmentInteraction(TopicSummary topicSummary) {
@ -166,34 +113,4 @@ public class MainActivity extends BaseActivity implements RecentFragment.OnListF
} }
//-------------------------------FragmentPagerAdapter END------------------------------------------- //-------------------------------FragmentPagerAdapter END-------------------------------------------
//-------------------------------------------LOGOUT-------------------------------------------------
/**
* Result toast will always display a success, because when user chooses logout all data are
* cleared regardless of the actual outcome
*/
private class LogoutTask extends AsyncTask<Void, Void, Integer> { //Attempt logout
ProgressDialog progressDialog;
protected Integer doInBackground(Void... voids) {
return sessionManager.logout();
}
protected void onPreExecute()
{ //Show a progress dialog until done
progressDialog = new ProgressDialog(MainActivity.this,
R.style.AppTheme_Dark_Dialog);
progressDialog.setCancelable(false);
progressDialog.setIndeterminate(true);
progressDialog.setMessage("Logging out...");
progressDialog.show();
}
protected void onPostExecute(Integer result)
{
Toast.makeText(getBaseContext(), "Logged out successfully!", Toast.LENGTH_LONG).show();
hideLogout();
progressDialog.dismiss();
}
}
//-----------------------------------------LOGOUT END-----------------------------------------------
} }

17
app/src/main/java/gr/thmmy/mthmmy/activities/TopicActivity.java

@ -13,6 +13,7 @@ import android.os.Handler;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBar;
import android.support.v7.widget.CardView; import android.support.v7.widget.CardView;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import android.util.SparseArray; import android.util.SparseArray;
@ -92,7 +93,6 @@ public class TopicActivity extends BaseActivity {
private static final String TAG = "TopicActivity"; private static final String TAG = "TopicActivity";
private String topicTitle; private String topicTitle;
private String parsedTitle; private String parsedTitle;
private ActionBar actionbar;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -102,6 +102,13 @@ public class TopicActivity extends BaseActivity {
Bundle extras = getIntent().getExtras(); Bundle extras = getIntent().getExtras();
topicTitle = getIntent().getExtras().getString("TOPIC_TITLE"); topicTitle = getIntent().getExtras().getString("TOPIC_TITLE");
//Initialize toolbar
toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setTitle(topicTitle);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
//Variables initialization //Variables initialization
postsLinearLayout = (LinearLayout) findViewById(R.id.posts_list); postsLinearLayout = (LinearLayout) findViewById(R.id.posts_list);
@ -112,10 +119,6 @@ public class TopicActivity extends BaseActivity {
postsList = new ArrayList<>(); postsList = new ArrayList<>();
actionbar = getSupportActionBar();
if (actionbar != null)
if(!Objects.equals(topicTitle, ""))
actionbar.setTitle(topicTitle);
firstPage = (ImageButton) findViewById(R.id.page_first_button); firstPage = (ImageButton) findViewById(R.id.page_first_button);
previousPage = (ImageButton) findViewById(R.id.page_previous_button); previousPage = (ImageButton) findViewById(R.id.page_previous_button);
@ -504,8 +507,8 @@ public class TopicActivity extends BaseActivity {
//Set topic title if not already present //Set topic title if not already present
if (topicTitle == null || Objects.equals(topicTitle, "")) { if (topicTitle == null || Objects.equals(topicTitle, "")) {
topicTitle = parsedTitle; topicTitle = parsedTitle;
if (actionbar != null){ if (toolbar != null){
actionbar.setTitle(topicTitle); toolbar.setTitle(topicTitle);
} }
} }

2
app/src/main/java/gr/thmmy/mthmmy/data/Post.java

@ -1,7 +1,5 @@
package gr.thmmy.mthmmy.data; package gr.thmmy.mthmmy.data;
import android.util.Log;
public class Post { public class Post {
//Standard info //Standard info
private final String thumbnailUrl; private final String thumbnailUrl;

18
app/src/main/res/layout/activity_topic.xml

@ -9,10 +9,28 @@
android:fitsSystemWindows="true" android:fitsSystemWindows="true"
tools:context=".activities.MainActivity"> tools:context=".activities.MainActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/appbar_padding_top"
android:theme="@style/ToolbarTheme">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/popupTheme">
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView <android.support.v4.widget.NestedScrollView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_gravity="top|start" android:layout_gravity="top|start"
android:layout_marginTop="64dp"
android:layout_marginBottom="50dp" android:layout_marginBottom="50dp"
android:background="@color/background" android:background="@color/background"
android:scrollbars="none" android:scrollbars="none"

22
app/src/main/res/menu/menu_main.xml

@ -1,22 +0,0 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".activities.MainActivity">
<item
android:id="@+id/action_login"
android:orderInCategory="100"
android:title="@string/login"
android:visible="false"
app:showAsAction="never"/>
<item
android:id="@+id/action_logout"
android:orderInCategory="200"
android:title="@string/logout"
android:visible="false"
app:showAsAction="never"/>
<item
android:id="@+id/action_about"
android:orderInCategory="300"
android:title="@string/about"
app:showAsAction="never"/>
</menu>
Loading…
Cancel
Save