Skip to content

Commit

Permalink
Wallpapers Activity
Browse files Browse the repository at this point in the history
  • Loading branch information
probelalkhan committed Apr 28, 2018
1 parent b0c94da commit 9e822bb
Show file tree
Hide file tree
Showing 13 changed files with 286 additions and 9 deletions.
29 changes: 29 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/build.gradle
Expand Up @@ -40,4 +40,4 @@ dependencies {
}


apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.gms.google-services'
4 changes: 3 additions & 1 deletion app/src/main/AndroidManifest.xml
Expand Up @@ -14,10 +14,12 @@
android:theme="@style/SplashScreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".activities.HomeActivity"></activity>
<activity android:name=".activities.HomeActivity" />
<activity android:name=".activities.WallpapersActivity"></activity>
</application>

</manifest>
@@ -0,0 +1,81 @@
package net.simplifiedcoding.wallpaperhub.activities;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.ProgressBar;

import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;

import net.simplifiedcoding.wallpaperhub.R;
import net.simplifiedcoding.wallpaperhub.adapters.WallpapersAdapter;
import net.simplifiedcoding.wallpaperhub.models.Wallpaper;

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

public class WallpapersActivity extends AppCompatActivity {

List<Wallpaper> wallpaperList;
RecyclerView recyclerView;
WallpapersAdapter adapter;

DatabaseReference dbWallpapers;
ProgressBar progressBar;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_wallpapers);

wallpaperList = new ArrayList<>();
recyclerView = findViewById(R.id.recycler_view);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
adapter = new WallpapersAdapter(this, wallpaperList);

recyclerView.setAdapter(adapter);

progressBar = findViewById(R.id.progressbar);


Intent intent = getIntent();
String category = intent.getStringExtra("category");

Toolbar toolbar = findViewById(R.id.toolbar);
toolbar.setTitle(category);
setSupportActionBar(toolbar);

dbWallpapers = FirebaseDatabase.getInstance().getReference("images")
.child(category);

progressBar.setVisibility(View.VISIBLE);
dbWallpapers.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
progressBar.setVisibility(View.GONE);
if(dataSnapshot.exists()){
for(DataSnapshot wallpaperSnapshot: dataSnapshot.getChildren()){
Wallpaper w = wallpaperSnapshot.getValue(Wallpaper.class);
wallpaperList.add(w);
}
adapter.notifyDataSetChanged();
}
}

@Override
public void onCancelled(DatabaseError databaseError) {

}
});

}
}
@@ -1,6 +1,7 @@
package net.simplifiedcoding.wallpaperhub.adapters;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
Expand All @@ -11,6 +12,7 @@
import com.bumptech.glide.Glide;

import net.simplifiedcoding.wallpaperhub.R;
import net.simplifiedcoding.wallpaperhub.activities.WallpapersActivity;
import net.simplifiedcoding.wallpaperhub.models.Category;

import java.util.List;
Expand Down Expand Up @@ -49,7 +51,7 @@ public int getItemCount() {
return categoryList.size();
}

class CategoryViewHolder extends RecyclerView.ViewHolder {
class CategoryViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {

TextView textView;
ImageView imageView;
Expand All @@ -59,6 +61,19 @@ public CategoryViewHolder(View itemView) {

textView = itemView.findViewById(R.id.text_view_cat_name);
imageView = itemView.findViewById(R.id.image_view);

itemView.setOnClickListener(this);
}

@Override
public void onClick(View view) {
int p = getAdapterPosition();
Category c = categoryList.get(p);

Intent intent = new Intent(mCtx, WallpapersActivity.class);
intent.putExtra("category", c.name);

mCtx.startActivity(intent);
}
}
}
@@ -0,0 +1,65 @@
package net.simplifiedcoding.wallpaperhub.adapters;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import net.simplifiedcoding.wallpaperhub.R;
import net.simplifiedcoding.wallpaperhub.models.Category;
import net.simplifiedcoding.wallpaperhub.models.Wallpaper;

import java.util.List;

/**
* Created by Belal on 4/21/2018.
*/

public class WallpapersAdapter extends RecyclerView.Adapter<WallpapersAdapter.CategoryViewHolder> {

private Context mCtx;
private List<Wallpaper> wallpaperList;

public WallpapersAdapter(Context mCtx, List<Wallpaper> wallpaperList) {
this.mCtx = mCtx;
this.wallpaperList = wallpaperList;
}

@Override
public CategoryViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(mCtx).inflate(R.layout.recyclerview_wallpapers, parent, false);
return new CategoryViewHolder(view);
}

@Override
public void onBindViewHolder(CategoryViewHolder holder, int position) {
Wallpaper w = wallpaperList.get(position);
holder.textView.setText(w.title);
Glide.with(mCtx)
.load(w.url)
.into(holder.imageView);
}

@Override
public int getItemCount() {
return wallpaperList.size();
}

class CategoryViewHolder extends RecyclerView.ViewHolder {

TextView textView;
ImageView imageView;

public CategoryViewHolder(View itemView) {
super(itemView);

textView = itemView.findViewById(R.id.text_view_title);
imageView = itemView.findViewById(R.id.image_view);
}
}
}
Expand Up @@ -9,6 +9,7 @@
import android.view.View;
import android.view.ViewGroup;
import android.widget.ProgressBar;
import android.widget.Toast;

import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
Expand Down
@@ -0,0 +1,11 @@
package net.simplifiedcoding.wallpaperhub.models;

public class Wallpaper {

public String title, desc, url;

public Wallpaper(){

}

}
43 changes: 43 additions & 0 deletions app/src/main/res/layout/activity_wallpapers.xml
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activities.WallpapersActivity">

<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary">

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|enterAlways"
app:title="@string/app_name"
app:titleTextColor="@color/colorTitle" />

</android.support.design.widget.AppBarLayout>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />

<ProgressBar
android:id="@+id/progressbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:visibility="gone" />

</RelativeLayout>

</android.support.design.widget.CoordinatorLayout>
29 changes: 29 additions & 0 deletions app/src/main/res/layout/recyclerview_wallpapers.xml
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="270dp">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

<ImageView
android:scaleType="fitXY"
android:id="@+id/image_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />

<TextView
android:text="Marvel"
android:background="@color/colorCategoryBackground"
android:textColor="@color/colorWhite"
android:textAlignment="center"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium"
android:layout_alignParentBottom="true"
android:id="@+id/text_view_title"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

</RelativeLayout>

</android.support.v7.widget.CardView>
2 changes: 1 addition & 1 deletion build.gradle
Expand Up @@ -7,7 +7,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.android.tools.build:gradle:3.1.2'


// NOTE: Do not place your application dependencies here; they belong
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
#Mon Apr 16 23:17:33 IST 2018
#Fri Apr 27 11:21:06 IST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip

0 comments on commit 9e822bb

Please sign in to comment.