تطبيق إعلانات بأندرويد و firebase الجزء الثاني
نظرة سريعة بالفيديو
1- إضافة Navigation View للتطبيق ديالنا
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 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:id="@+id/drawerLayout"
android:fitsSystemWindows="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:openDrawer="start">
<include layout="@layout/activity_main"></include>
<android.support.design.widget.NavigationView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/navView"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header"
app:menu="@menu/nav_menu"
>
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
2- إضافة ملف عرض الإعلانات ف recycler view
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
app:cardBackgroundColor="@android:color/white"
app:cardCornerRadius="5dp"
app:cardElevation="2dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="150dp"
android:scaleType="centerCrop"
tools:src="@drawable/layer" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp">
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?android:selectableItemBackground"
android:padding="10dp"
tools:text="This is the title"
android:fontFamily="sans-serif"
android:maxLines="1"
android:textColor="#333"
android:textSize="14sp" />
</LinearLayout>
<LinearLayout
android:layout_marginTop="-30dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/city"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:selectableItemBackground"
android:padding="10dp"
tools:text="London"
android:fontFamily="sans-serif"
android:textColor="#c1c1c1"
android:textSize="10sp" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
3- إضافة toolbar للتطبيق ديالنا
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:elevation="5dp"
android:background="@color/colorPrimary"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
</android.support.v7.widget.Toolbar>
4- إضافة la classe AdInfo.java
package models;
import java.io.Serializable;
/**
* Created by belasri on 25/11/2017.
*/
public class AdInfo implements Serializable {
private static final long id = 1L;
private String title;
private String desc;
private String city;
private String imageUrl;
private int userId;
private String AdId;
public AdInfo(String AdId,String title,String desc, String city,String imageUrl) {
title = title;
desc = desc;
city = city;
imageUrl = imageUrl;
AdId = AdId;
}
public AdInfo(){
}
public static long getId() {
return id;
}
public String getAdId() {
return AdId;
}
public void setAdId(String adId) {
AdId = adId;
}
public void setTitle(String title) {
this.title = title;
}
public void setCity(String city) {
this.city = city;
}
public void setUserId(int userId) {
this.userId = userId;
}
public String getTitle() {
return title;
}
public String getDesc() {
return desc;
}
public String getImageUrl() {
return imageUrl;
}
public void setImageUrl(String imageUrl) {
this.imageUrl = imageUrl;
}
public void setDesc(String desc) {
this.desc = desc;
}
public String getCity() {
return city;
}
public int getUserId() {
return userId;
}
}
5- إضافة la classe User.java
package models;
/**
* Created by belasri on 03/12/2017.
*/
public class User {
private String fullname;
private String email;
private String password;
private int city_id;
private String adress;
private int tel;
private String user_id;
public User(String user_id,String fullname, String email,String password,int city_id,int tel,String adress){
user_id = user_id;
fullname = fullname;
email = email;
password = password;
city_id = city_id;
tel = tel;
adress = adress;
}
public User(){
}
public String getUser_id() {
return user_id;
}
public void setUser_id(String user_id) {
this.user_id = user_id;
}
public String getFullname() {
return fullname;
}
public void setFullname(String fullname) {
this.fullname = fullname;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public int getCity_id() {
return city_id;
}
public void setCity_id(int city_id) {
this.city_id = city_id;
}
public String getAdress() {
return adress;
}
public void setAdress(String adress) {
this.adress = adress;
}
public int getTel() {
return tel;
}
public void setTel(int tel) {
this.tel = tel;
}
}