Skip to content

Commit

Permalink
v1.0.0-alpha push
Browse files Browse the repository at this point in the history
Signed-off-by: chankruze <chankruze@gmail.com>
  • Loading branch information
chankruze committed Jun 13, 2019
1 parent c0f3e13 commit d1f56c5
Show file tree
Hide file tree
Showing 60 changed files with 671 additions and 385 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ dependencies {
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.squareup.okhttp3:okhttp:4.0.0-RC1'
implementation 'com.squareup.picasso:picasso:2.71828'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
package="in.geekofia.blog">

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.INTERNET" />

<application
android:allowBackup="true"
Expand Down
Binary file added app/src/main/ic_launcher-web.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
148 changes: 114 additions & 34 deletions app/src/main/java/in/geekofia/blog/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
package in.geekofia.blog;


import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomNavigationView;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ListView;
import android.widget.ProgressBar;
Expand All @@ -29,37 +35,22 @@
import okhttp3.Request;
import okhttp3.Response;

public class MainActivity extends AppCompatActivity {
public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener{

private Toolbar mTopToolbar;
private DrawerLayout mDrawer;
private PostAdapter mAdapter;
private ListView mLatestPostsListView;
private Button mRetryButton;
private ProgressBar mLoadingIndicator;
private TextView mEmptyStateTextView;
private TextView mEmptyStateTextView, mDrawerAppVersion;

private static final String GEEKOFIA_BLOG_ENDPOINT = "https://blog.geekofia.in/api/v1";
private static final String LOG_TAG = MainActivity.class.getName();

private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
= new BottomNavigationView.OnNavigationItemSelectedListener() {

@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.navigation_home:
mTopToolbar.setTitle(R.string.title_home);
return true;
case R.id.navigation_dashboard:
mTopToolbar.setTitle(R.string.title_dashboard);
return true;
case R.id.navigation_notifications:
mTopToolbar.setTitle(R.string.title_notifications);
return true;
}
return false;
}
};
int versionCode = BuildConfig.VERSION_CODE;
String versionName = BuildConfig.VERSION_NAME;


@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -74,17 +65,45 @@ protected void onCreate(Bundle savedInstanceState) {
}

private void initializeViews() {
// Bottom Navigation Bar
BottomNavigationView navigation = findViewById(R.id.id_BottomNavigation);
navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);

// Toolbar
mTopToolbar = findViewById(R.id.id_Toolbar);
mTopToolbar = findViewById(R.id.toolbar);
setSupportActionBar(mTopToolbar);

mDrawer = findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, mDrawer, mTopToolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
mDrawer.addDrawerListener(toggle);
toggle.syncState();

NavigationView navigationView = findViewById(R.id.nav_view);
View hView = navigationView.getHeaderView(0);

TextView appVersion = hView.findViewById(R.id.drawer_app_version);
appVersion.setText("Version : " + versionName);

TextView appDev = hView.findViewById(R.id.drawer_app_dev);
appDev.setText("Developer : chankruze");

// Latest Posts List
mLatestPostsListView = findViewById(R.id.id_LatestPostsList);

mLatestPostsListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
// Find the current earthquake that was clicked on
Post currentPost = mAdapter.getItem(position);

// Convert the String URL into a URI object (to pass into the Intent constructor)
Uri postUri = Uri.parse(currentPost.getmPostUrl());

// Create a new intent to view the earthquake URI
Intent websiteIntent = new Intent(Intent.ACTION_VIEW, postUri);

// Send the intent to launch a new activity
startActivity(websiteIntent);
}
});

// Loading Indicator
mLoadingIndicator = findViewById(R.id.id_LoadingIndicator);

Expand All @@ -106,7 +125,16 @@ public void run() {
}, 1000);
}
});
}

@Override
public void onBackPressed() {
DrawerLayout drawer = findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}

private void startLoader() {
Expand All @@ -115,6 +143,7 @@ private void startLoader() {
syncLatestPosts();
} else {
mLoadingIndicator.setVisibility(View.GONE);
mEmptyStateTextView.setVisibility(View.VISIBLE);
mEmptyStateTextView.setText(R.string.no_internet_connection);
mRetryButton.setVisibility(View.VISIBLE);
}
Expand Down Expand Up @@ -145,6 +174,7 @@ public void run() {
ArrayList<Post> posts = PostUtils.extractPosts(myResponse);
mAdapter = new PostAdapter(MainActivity.this, posts);
mLoadingIndicator.setVisibility(View.GONE);
mEmptyStateTextView.setVisibility(View.GONE);
mLatestPostsListView.setAdapter(mAdapter);
}
});
Expand Down Expand Up @@ -174,12 +204,62 @@ public boolean onOptionsItemSelected(MenuItem item) {
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();

//noinspection SimplifiableIfStatement
if (id == R.id.action_favorite) {
Toast.makeText(MainActivity.this, "Thanks for your $100 donation !", Toast.LENGTH_LONG).show();
return true;
}
// //noinspection SimplifiableIfStatement
// if (id == R.id) {
// Toast.makeText(MainActivity.this, "Thanks for your $100 donation !", Toast.LENGTH_LONG).show();
// return true;
// }

return super.onOptionsItemSelected(item);
}

@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
// int id = item.getItemId();

switch (item.getItemId()) {
case R.id.nav_LatestPosts:
mTopToolbar.setTitle(R.string.title_latest_posts);
return true;
case R.id.nav_Categories:
mTopToolbar.setTitle(R.string.title_categories);
return true;
case R.id.nav_Tags:
mTopToolbar.setTitle(R.string.title_tags);
return true;
case R.id.nav_Share:
return true;
case R.id.nav_Contact:
return true;
case R.id.nav_Author:
return true;
case R.id.nav_Sponsor:
return true;
}

DrawerLayout drawer = findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}

@Override
protected void onRestart() {
super.onRestart();

if (!isConnected()){
try{
mAdapter.clear();
}catch (Exception e){
Toast.makeText(MainActivity.this, "Error Refreshing Posts!", Toast.LENGTH_SHORT).show();
}
startLoader();
} else{
mRetryButton.setVisibility(View.GONE);
mEmptyStateTextView.setText("Refreshing Posts ...");
syncLatestPosts();
}

}
}
15 changes: 12 additions & 3 deletions app/src/main/java/in/geekofia/blog/Post.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
import java.util.List;

public class Post {
private String mPostTitle, mPostDate, mPostDescription;
private String mPostUrl;
private String mPostTitle, mPostDate, mPostDescription, mAuthor, mThumbnailUrl, mPostUrl;
private List<String> mCategories, mTags;

public Post(String mPostTitle, String mPostDate, String mPostDescription, String mPostUrl, List<String> mCategories, List<String> mTags) {
public Post(String mPostTitle, String mPostDate, String mPostDescription, String mAuthor,String mThumbnailUrl, String mPostUrl, List<String> mCategories, List<String> mTags) {
this.mPostTitle = mPostTitle;
this.mPostDate = mPostDate;
this.mPostDescription = mPostDescription;
this.mAuthor = mAuthor;
this.mThumbnailUrl = mThumbnailUrl;
this.mPostUrl = mPostUrl;
this.mCategories = mCategories;
this.mTags = mTags;
Expand All @@ -28,6 +29,14 @@ public String getmPostDescription() {
return mPostDescription;
}

public String getmAuthor(){
return mAuthor;
}

public String getmThumbnailUrl() {
return mThumbnailUrl;
}

public String getmPostUrl() {
return mPostUrl;
}
Expand Down
22 changes: 19 additions & 3 deletions app/src/main/java/in/geekofia/blog/PostAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,20 @@
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;

import java.util.ArrayList;
import java.util.Objects;

public class PostAdapter extends ArrayAdapter<Post> {

private TextView mPostTitleField, mPostDateField, mPostDescriptionField, mPostUrlField;
private TextView mPostTitleField, mPostDateField, mPostDescriptionField, mAuthorField;
private ImageView mThumbnailView;
private String mPostUrl;
private static final String PROTO_ONE = "https://", PROTO_TWO = "http://", DOMAIN_URL = "https://blog.geekofia.in";

public PostAdapter(Activity context, ArrayList<Post> posts) {
super(context, 0, posts);
Expand All @@ -37,12 +43,22 @@ public View getView(int position, View convertView, ViewGroup parent) {
mPostDescriptionField = listItemView.findViewById(R.id.post_description);
mPostDescriptionField.setText(currentPost.getmPostDescription());

// mPostUrlField = listItemView.findViewById(R.id.post_url);
// mPostUrlField.setText((CharSequence) currentPost.getmPostUrl());
mAuthorField = listItemView.findViewById(R.id.post_author);
mAuthorField.setText(currentPost.getmAuthor());

mPostDateField = listItemView.findViewById(R.id.post_date);
mPostDateField.setText(currentPost.getmPostDate());

mThumbnailView = listItemView.findViewById(R.id.post_thumbnail);
mPostUrl = currentPost.getmThumbnailUrl();

if (mPostUrl.toLowerCase().contains(PROTO_ONE) || mPostUrl.toLowerCase().contains(PROTO_TWO)){
Picasso.get().load(mPostUrl).into(mThumbnailView);
} else{
mPostUrl = DOMAIN_URL + mPostUrl;
Picasso.get().load(mPostUrl).into(mThumbnailView);
}

return listItemView;
}
}
4 changes: 3 additions & 1 deletion app/src/main/java/in/geekofia/blog/PostUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public static ArrayList<Post> extractPosts(String JSON_RESPONSE) {
String desc = CurrentPost.getString("desc");
String date = CurrentPost.getString("date");
String url = CurrentPost.getString("url");
String author = CurrentPost.getString("author");
String thumbnail = CurrentPost.getString("thumbnail");
String categoryArray = CurrentPost.getString("category");
String tagsArray = CurrentPost.getString("tags");

Expand All @@ -52,7 +54,7 @@ public static ArrayList<Post> extractPosts(String JSON_RESPONSE) {
// tags.add(tagsArray.getString(c));
// }

Post newPost = new Post(title, date, desc, url, null, null);
Post newPost = new Post(title, date, desc, author, thumbnail, url,null, null);
latestPosts.add(newPost);
}

Expand Down
17 changes: 17 additions & 0 deletions app/src/main/res/drawable/ic_author.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FF000000"
android:pathData="M0,0h24v24h-24z"
android:strokeAlpha="0"
android:fillAlpha="0"/>
<path
android:fillColor="#FF000000"
android:pathData="M19,20H5a1,1 0,0 0,0 2h14a1,1 0,0 0,0 -2z"/>
<path
android:fillColor="#FF000000"
android:pathData="M5,18h0.09l4.17,-0.38a2,2 0,0 0,1.21 -0.57l9,-9a1.92,1.92 0,0 0,-0.07 -2.71L16.66,2.6A2,2 0,0 0,14 2.53l-9,9a2,2 0,0 0,-0.57 1.21L4,16.91a1,1 0,0 0,0.29 0.8A1,1 0,0 0,5 18zM15.27,4L18,6.73l-2,1.95L13.32,6zM6.37,12.91L12,7.32l2.7,2.7 -5.6,5.6 -3,0.28z"/>
</vector>
11 changes: 0 additions & 11 deletions app/src/main/res/drawable/ic_beer.xml

This file was deleted.

14 changes: 14 additions & 0 deletions app/src/main/res/drawable/ic_category.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FF000000"
android:pathData="M0,0h24v24h-24z"
android:strokeAlpha="0"
android:fillAlpha="0"/>
<path
android:fillColor="#FF000000"
android:pathData="M19.5,20.5h-15A2.47,2.47 0,0 1,2 18.07V5.93A2.47,2.47 0,0 1,4.5 3.5h4.6a1,1 0,0 1,0.77 0.37l2.6,3.18h7A2.47,2.47 0,0 1,22 9.48v8.59a2.47,2.47 0,0 1,-2.5 2.43zM4,13.76v4.31a0.46,0.46 0,0 0,0.5 0.43h15a0.46,0.46 0,0 0,0.5 -0.43V9.48a0.46,0.46 0,0 0,-0.5 -0.43H12a1,1 0,0 1,-0.77 -0.37L8.63,5.5H4.5a0.46,0.46 0,0 0,-0.5 0.43z"/>
</vector>
Loading

0 comments on commit d1f56c5

Please sign in to comment.