Skip to content

Commit d709b6f

Browse files
committed
Finish Release 1.0.0
2 parents cdbf119 + 6f3fb5c commit d709b6f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+2330
-398
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,4 @@ captures/
4242

4343
### Android Studio default
4444
.externalNativeBuild
45-
.idea/
45+
.idea/

app/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,7 @@ dependencies {
3333
compile 'org.slf4j:slf4j-api:1.7.12'
3434
compile 'org.slf4j:slf4j-simple:1.7.12'
3535
compile 'com.android.support:design:24.2.1'
36+
compile 'com.android.support:support-v4:24.2.1'
37+
compile 'com.android.support:recyclerview-v7:24.2.1'
3638
testCompile 'junit:junit:4.12'
3739
}

app/src/main/AndroidManifest.xml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,26 @@
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
package="ch.hsr.mge.gadgeothek">
44

5-
<!-- To auto-complete the email text field in the login form with the user's emails -->
6-
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
7-
<uses-permission android:name="android.permission.READ_PROFILE" />
8-
<uses-permission android:name="android.permission.READ_CONTACTS" />
5+
<uses-permission android:name="android.permission.INTERNET" />
96

107
<application
118
android:allowBackup="true"
129
android:icon="@mipmap/ic_launcher"
1310
android:label="@string/app_name"
1411
android:supportsRtl="true"
1512
android:theme="@style/AppTheme">
16-
<activity android:name=".MainActivity">
13+
<activity
14+
android:name=".MainActivity"
15+
android:theme="@style/AppTheme.NoActionBar">
16+
</activity>
17+
<activity android:name=".LoginActivity"
18+
android:label="@string/app_name">
1719
<intent-filter>
1820
<action android:name="android.intent.action.MAIN" />
1921

2022
<category android:name="android.intent.category.LAUNCHER" />
2123
</intent-filter>
2224
</activity>
23-
<activity
24-
android:name=".LoginActivity"
25-
android:label="@string/title_activity_login"></activity>
2625
</application>
2726

2827
</manifest>
Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
package ch.hsr.mge.gadgeothek;
2+
3+
import android.app.Activity;
4+
import android.app.Fragment;
5+
import android.content.Context;
6+
import android.os.Bundle;
7+
import android.view.LayoutInflater;
8+
import android.view.View;
9+
import android.view.ViewGroup;
10+
import android.widget.Button;
11+
import android.widget.ImageView;
12+
import android.widget.TextView;
13+
14+
import ch.hsr.mge.gadgeothek.domain.Gadget;
15+
import ch.hsr.mge.gadgeothek.domain.Loan;
16+
import ch.hsr.mge.gadgeothek.domain.Reservation;
17+
import ch.hsr.mge.gadgeothek.service.IDecoratorService;
18+
import ch.hsr.mge.gadgeothek.service.LocalDecoratorService;
19+
20+
21+
/**
22+
* A simple {@link Fragment} subclass.
23+
* Activities that contain this fragment must implement the
24+
* {@link IHandleGadgetDetailFragment} interface
25+
* to handle interaction events.
26+
*/
27+
public class GadgetDetailFragment extends Fragment implements View.OnClickListener {
28+
29+
private IHandleGadgetDetailFragment mListener;
30+
private IDecoratorService decorator;
31+
32+
public enum DetailType {
33+
GADGET, RESERVATION, LOAN
34+
}
35+
36+
TextView mInventoryNumber;
37+
TextView mNameView;
38+
TextView mManufacturerView;
39+
TextView mPrice;
40+
TextView mConditionView;
41+
ImageView mManufacturerLogoView;
42+
43+
TextView mLoanSince;
44+
TextView mLoanSinceLabel;
45+
46+
Button mAddReservation;
47+
Button mDeleteReservation;
48+
49+
public GadgetDetailFragment() {
50+
// Required empty public constructor
51+
}
52+
53+
54+
@Override
55+
public View onCreateView(LayoutInflater inflater, ViewGroup container,
56+
Bundle savedInstanceState) {
57+
decorator = LocalDecoratorService.getDecoratorService();
58+
return inflater.inflate(R.layout.fragment_gadget_detail, container, false);
59+
60+
}
61+
62+
@Override
63+
public void onViewCreated(View view, Bundle savedInstanceState) {
64+
super.onViewCreated(view, savedInstanceState);
65+
mInventoryNumber = (TextView) getView().findViewById(R.id.gadget_inventorynumber);
66+
mNameView = (TextView) getView().findViewById(R.id.gadget_name);
67+
mManufacturerView = (TextView) getView().findViewById(R.id.gadget_manufacturer);
68+
mPrice = (TextView) getView().findViewById(R.id.gadget_price);
69+
mConditionView = (TextView) getView().findViewById(R.id.gadget_condition);
70+
71+
mLoanSince = (TextView) getView().findViewById(R.id.loan_since);
72+
mLoanSinceLabel = (TextView) getView().findViewById(R.id.labelLoanSince);
73+
74+
mAddReservation = (Button) getView().findViewById(R.id.btn_add_reservation);
75+
mDeleteReservation = (Button) getView().findViewById(R.id.btn_delete_reservation);
76+
77+
mManufacturerLogoView = (ImageView) getView().findViewById(R.id.gadget_manufacturer_logo);
78+
79+
mAddReservation.setOnClickListener(this);
80+
mDeleteReservation.setOnClickListener(this);
81+
82+
//
83+
Gadget gadget = null;
84+
switch (mListener.getDetailType()){
85+
case GADGET:
86+
gadget = mListener.getDetailGadget();
87+
88+
mLoanSince.setVisibility(View.GONE);
89+
mLoanSinceLabel.setVisibility(View.GONE);
90+
91+
mAddReservation.setVisibility(View.VISIBLE);
92+
mDeleteReservation.setVisibility(View.GONE);
93+
break;
94+
case RESERVATION:
95+
gadget = mListener.getDetailReservation().getGadget();
96+
97+
mLoanSince.setVisibility(View.GONE);
98+
mLoanSinceLabel.setVisibility(View.GONE);
99+
100+
mAddReservation.setVisibility(View.GONE);
101+
mDeleteReservation.setVisibility(View.VISIBLE);
102+
break;
103+
case LOAN:
104+
gadget = mListener.getDetailLoan().getGadget();
105+
106+
mLoanSince.setText(mListener.getDetailLoan().getPickupDate().toString());
107+
mLoanSince.setVisibility(View.VISIBLE);
108+
mLoanSinceLabel.setVisibility(View.VISIBLE);
109+
110+
mAddReservation.setVisibility(View.GONE);
111+
mDeleteReservation.setVisibility(View.GONE);
112+
break;
113+
}
114+
115+
mInventoryNumber.setText(gadget.getInventoryNumber());
116+
mNameView.setText(gadget.getName());
117+
mManufacturerView.setText(gadget.getManufacturer());
118+
mPrice.setText(Double.toString(gadget.getPrice()));
119+
mConditionView.setText(gadget.getCondition().toString());
120+
mManufacturerLogoView.setImageResource(decorator.getDrawableIdForManufacturerName(gadget.getManufacturer()));
121+
122+
}
123+
124+
@Override
125+
public void onAttach(Context context) {
126+
super.onAttach(context);
127+
_onAttach_API_independent(context);
128+
}
129+
/**
130+
* Code duplication for API Level 22 support
131+
*/
132+
public void onAttach(Activity activity) {
133+
super.onAttach(activity);
134+
_onAttach_API_independent(activity);
135+
}
136+
137+
private void _onAttach_API_independent(Context context){
138+
if (context instanceof IHandleGadgetDetailFragment) {
139+
this.mListener = (IHandleGadgetDetailFragment) context;
140+
} else {
141+
throw new RuntimeException(context.toString()
142+
+ " must implement IHandleGadgetDetailFragment");
143+
}
144+
}
145+
146+
@Override
147+
public void onDetach() {
148+
super.onDetach();
149+
mListener = null;
150+
}
151+
152+
@Override
153+
public void onClick(View view) {
154+
switch (view.getId()){
155+
case R.id.btn_add_reservation: {
156+
mListener.onReserveGadget();
157+
break;
158+
}
159+
case R.id.btn_delete_reservation: {
160+
mListener.onDeleteReservation();
161+
break;
162+
}
163+
164+
}
165+
}
166+
167+
/**
168+
* This interface must be implemented by activities that contain this
169+
* fragment to allow an interaction in this fragment to be communicated
170+
* to the activity and potentially other fragments contained in that
171+
* activity.
172+
* <p>
173+
* See the Android Training lesson <a href=
174+
* "http://developer.android.com/training/basics/fragments/communicating.html"
175+
* >Communicating with Other Fragments</a> for more information.
176+
*/
177+
public interface IHandleGadgetDetailFragment {
178+
Gadget getDetailGadget();
179+
Reservation getDetailReservation();
180+
Loan getDetailLoan();
181+
DetailType getDetailType();
182+
void onReserveGadget();
183+
void onDeleteReservation();
184+
}
185+
}
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
package ch.hsr.mge.gadgeothek;
2+
3+
import android.support.v7.widget.RecyclerView;
4+
import android.view.LayoutInflater;
5+
import android.view.View;
6+
import android.view.ViewGroup;
7+
import android.widget.ImageView;
8+
import android.widget.TextView;
9+
10+
import java.util.ArrayList;
11+
import java.util.List;
12+
13+
import ch.hsr.mge.gadgeothek.domain.Gadget;
14+
import ch.hsr.mge.gadgeothek.domain.Loan;
15+
import ch.hsr.mge.gadgeothek.domain.Reservation;
16+
import ch.hsr.mge.gadgeothek.service.IDecoratorService;
17+
import ch.hsr.mge.gadgeothek.service.LocalDecoratorService;
18+
19+
public class GadgetsAdapter extends RecyclerView.Adapter<GadgetsAdapter.MyViewHolder> {
20+
private List<Gadget> gadgetList;
21+
private List<Loan> loansList;
22+
private List<Reservation> reservationList;
23+
24+
private IDecoratorService decorator;
25+
26+
27+
public class MyViewHolder extends RecyclerView.ViewHolder {
28+
public TextView name, manufacturer;
29+
public ImageView manufacturerLogo;
30+
31+
public MyViewHolder(View view) {
32+
super(view);
33+
name = (TextView) view.findViewById(R.id.gadget_list_name);
34+
manufacturer = (TextView) view.findViewById(R.id.gadget_list_manufacturer);
35+
manufacturerLogo = (ImageView) view.findViewById(R.id.gadget_list_manufacturer_logo);
36+
}
37+
}
38+
39+
40+
public GadgetsAdapter() {
41+
this.decorator = LocalDecoratorService.getDecoratorService();
42+
this.gadgetList = new ArrayList<>();
43+
this.loansList = new ArrayList<>();
44+
this.reservationList = new ArrayList<>();
45+
}
46+
47+
public void setGadgetList(List<Gadget> gadgetList){
48+
this.reservationList.clear();
49+
this.loansList.clear();
50+
51+
this.gadgetList = gadgetList;
52+
53+
this.notifyDataSetChanged();
54+
}
55+
56+
public void setLoanList(List<Loan> loanList){
57+
gadgetList.clear();
58+
this.reservationList.clear();
59+
60+
this.loansList = loanList;
61+
62+
for (Loan loan : loanList) {
63+
gadgetList.add(loan.getGadget());
64+
}
65+
66+
this.notifyDataSetChanged();
67+
}
68+
69+
public void setReservationList(List<Reservation> reservationList){
70+
gadgetList.clear();
71+
this.loansList.clear();
72+
73+
this.reservationList = reservationList;
74+
75+
for (Reservation reservation : reservationList) {
76+
gadgetList.add(reservation.getGadget());
77+
}
78+
this.notifyDataSetChanged();
79+
}
80+
81+
public Gadget getGadgetByPosition(int position){
82+
return gadgetList.get(position);
83+
}
84+
85+
public Reservation getReservationByPosition(int position) {
86+
return reservationList.get(position);
87+
}
88+
89+
public Loan getLoanByPosition(int position){
90+
return loansList.get(position);
91+
}
92+
93+
@Override
94+
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
95+
View itemView = LayoutInflater.from(parent.getContext())
96+
.inflate(R.layout.gadget_list_row, parent, false);
97+
98+
return new MyViewHolder(itemView);
99+
}
100+
101+
@Override
102+
public void onBindViewHolder(MyViewHolder holder, int position) {
103+
Gadget gadget = gadgetList.get(position);
104+
holder.name.setText(gadget.getName());
105+
holder.manufacturer.setText(gadget.getManufacturer());
106+
int imageID = decorator.getDrawableIdForManufacturerName(gadget.getManufacturer());
107+
holder.manufacturerLogo.setImageResource(imageID);
108+
}
109+
110+
@Override
111+
public int getItemCount() {
112+
return gadgetList.size();
113+
}
114+
115+
}

0 commit comments

Comments
 (0)