Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
hostel and student list is now fetched from realm
* also bumped dependencies * fixed layout bugs in student list * NOTE : We're using `Student` class to model student data. So deleted `ResidentModel`
- Loading branch information
Showing
11 changed files
with
133 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 0 additions & 29 deletions
29
app/src/main/java/com/macbitsgoa/prdrive/ResidentModel.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 23 additions & 6 deletions
29
app/src/main/java/com/macbitsgoa/prdrive/activities/ResidentActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,44 @@ | ||
package com.macbitsgoa.prdrive.activities; | ||
|
||
import android.app.Activity; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.os.Bundle; | ||
|
||
import com.macbitsgoa.prdrive.R; | ||
import com.macbitsgoa.prdrive.adapters.ResidentAdapter; | ||
|
||
import androidx.recyclerview.widget.LinearLayoutManager; | ||
import androidx.recyclerview.widget.RecyclerView; | ||
|
||
|
||
public class ResidentActivity extends Activity { | ||
|
||
public static final String INTENT_KEY_HOSTEL_NAME = ResidentActivity.class.getName() + ".intent.hostelName"; | ||
|
||
/** | ||
* Use this method to launch this activity correctly. | ||
* | ||
* @param parent from which this is to be launched. | ||
* @param hostelName name of the target hostel. | ||
*/ | ||
public static void launchHostel(Context parent, String hostelName) { | ||
Intent intent = new Intent(parent, ResidentActivity.class); | ||
intent.putExtra(INTENT_KEY_HOSTEL_NAME, hostelName); | ||
parent.startActivity(intent); | ||
} | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_resident); | ||
|
||
Intent source = getIntent(); | ||
final String hostelName = source.getStringExtra(INTENT_KEY_HOSTEL_NAME); | ||
RecyclerView rv; | ||
|
||
rv = findViewById(R.id.list_rv); | ||
rv.setLayoutManager(new LinearLayoutManager(ResidentActivity.this)); | ||
rv.setHasFixedSize(false); | ||
ResidentAdapter residentAdapter = new ResidentAdapter(ResidentActivity.this); | ||
ResidentAdapter residentAdapter = new ResidentAdapter(hostelName); | ||
rv.setAdapter(residentAdapter); | ||
|
||
|
||
} | ||
} | ||
} |
34 changes: 25 additions & 9 deletions
34
app/src/main/java/com/macbitsgoa/prdrive/adapters/HomeAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,53 @@ | ||
package com.macbitsgoa.prdrive.adapters; | ||
|
||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
|
||
import com.macbitsgoa.prdrive.R; | ||
import com.macbitsgoa.prdrive.Student; | ||
import com.macbitsgoa.prdrive.viewholders.HomeViewHolder; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.recyclerview.widget.RecyclerView; | ||
import io.realm.Realm; | ||
import io.realm.RealmQuery; | ||
import io.realm.RealmResults; | ||
|
||
|
||
public class HomeAdapter extends RecyclerView.Adapter<HomeViewHolder> { | ||
|
||
|
||
private String hostelNames[] = {"AH1", "AH2", "AH3", "AH4", "AH5", "AH6", "AH7", | ||
"AH8", "AH9", "CH1", "CH2", "CH3", "CH4", "CH5", "CH6", "CH7", "DH1", "DH2"}; | ||
|
||
|
||
private List<String> hostelNames; | ||
|
||
public HomeAdapter() { | ||
hostelNames = new ArrayList<>(); | ||
Realm realm = Realm.getDefaultInstance(); | ||
RealmQuery<Student> query = realm.where(Student.class).distinct("hostel"); | ||
RealmResults<Student> results = query.findAll(); | ||
for (Student s : results) { | ||
hostelNames.add(s.hostel); | ||
} | ||
realm.close(); | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public HomeViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { | ||
return new HomeViewHolder(View.inflate(parent.getContext(), R.layout.item_format_home, null), | ||
parent.getContext()); | ||
View v = LayoutInflater.from(parent.getContext()) | ||
.inflate(R.layout.item_format_home, parent, false); | ||
return new HomeViewHolder(v); | ||
} | ||
|
||
@Override | ||
public void onBindViewHolder(@NonNull HomeViewHolder holder, int position) { | ||
holder.populate(hostelNames[position]); | ||
holder.populate(hostelNames.get(position)); | ||
} | ||
|
||
@Override | ||
public int getItemCount() { | ||
return hostelNames.length; | ||
return hostelNames.size(); | ||
} | ||
} |
31 changes: 19 additions & 12 deletions
31
app/src/main/java/com/macbitsgoa/prdrive/adapters/ResidentAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,45 @@ | ||
package com.macbitsgoa.prdrive.adapters; | ||
|
||
import android.content.Context; | ||
import android.view.View; | ||
import android.view.LayoutInflater; | ||
import android.view.ViewGroup; | ||
|
||
import com.macbitsgoa.prdrive.R; | ||
import com.macbitsgoa.prdrive.Student; | ||
import com.macbitsgoa.prdrive.viewholders.ResidentViewHolder; | ||
|
||
import java.util.List; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.recyclerview.widget.RecyclerView; | ||
|
||
import static com.macbitsgoa.prdrive.StaticHelperClass.merchModelList; | ||
import io.realm.Realm; | ||
import io.realm.RealmQuery; | ||
import io.realm.RealmResults; | ||
|
||
public class ResidentAdapter extends RecyclerView.Adapter<ResidentViewHolder> { | ||
Context context; | ||
|
||
public ResidentAdapter(Context ctx) { | ||
this.context = ctx; | ||
private List<Student> students; | ||
|
||
public ResidentAdapter(String hostel) { | ||
Realm realm = Realm.getDefaultInstance(); | ||
RealmQuery<Student> query = realm.where(Student.class).equalTo("hostel", hostel); | ||
RealmResults<Student> results = query.findAll(); | ||
students = realm.copyFromRealm(results); | ||
realm.close(); | ||
} | ||
|
||
@Override | ||
public ResidentViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { | ||
return new ResidentViewHolder(View.inflate(parent.getContext(), R.layout.item_format_resident, null) , | ||
parent.getContext()); | ||
return new ResidentViewHolder(LayoutInflater.from(parent.getContext()) | ||
.inflate(R.layout.item_format_resident, parent, false)); | ||
} | ||
|
||
@Override | ||
public void onBindViewHolder(@NonNull ResidentViewHolder holder, int position) { | ||
|
||
|
||
holder.populate(students.get(position)); | ||
} | ||
|
||
@Override | ||
public int getItemCount() { | ||
return merchModelList.size(); | ||
return students.size(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.