22
33import android .content .Intent ;
44import android .os .Bundle ;
5+ import android .view .Menu ;
56import android .view .MenuItem ;
67
78import androidx .annotation .NonNull ;
89import androidx .appcompat .app .AppCompatActivity ;
10+ import androidx .recyclerview .widget .LinearLayoutManager ;
911import androidx .recyclerview .widget .RecyclerView ;
1012
11- import com .google .android .material .floatingactionbutton .FloatingActionButton ;
1213
1314import org .json .JSONArray ;
1415import org .json .JSONException ;
@@ -17,8 +18,8 @@ public class PolicyPremiumsActivity extends AppCompatActivity {
1718
1819 ClientAndroidInterface ca ;
1920 RecyclerView recyclerView ;
20- FloatingActionButton btnAdd ;
2121 private int familyId , policyId , regionId , districtId ;
22+ String page = "premiums" ;
2223
2324 @ Override
2425 protected void onCreate (Bundle savedInstanceState ) {
@@ -31,48 +32,50 @@ protected void onCreate(Bundle savedInstanceState) {
3132 ca = new ClientAndroidInterface (this );
3233 familyId = getIntent ().getIntExtra ("FamilyId" , 0 );
3334 policyId = getIntent ().getIntExtra ("PolicyId" , 0 );
34- policyId = getIntent ().getIntExtra ("RegionId" , 0 );
35- policyId = getIntent ().getIntExtra ("DistrictId" , 0 );
35+ regionId = getIntent ().getIntExtra ("RegionId" , 0 );
36+ districtId = getIntent ().getIntExtra ("DistrictId" , 0 );
3637 initViews ();
37- setupListenners ();
3838 loadPremiums ();
3939
4040 }
4141
42+ @ Override
43+ public boolean onCreateOptionsMenu (Menu menu ) {
44+ getMenuInflater ().inflate (R .menu .menu_add , menu );
45+ return true ;
46+ }
47+
4248 @ Override
4349 public boolean onOptionsItemSelected (@ NonNull MenuItem item ) {
4450 if (item .getItemId () == android .R .id .home ) {
4551 finish ();
4652 return true ;
4753 }
48- return super .onOptionsItemSelected (item );
49- }
50-
51- private void initViews (){
52- btnAdd = findViewById (R .id .btnAddNewPremiums );
53- recyclerView = findViewById (R .id .recyclerPremiums );
54- }
55-
56- private void setupListenners (){
57- btnAdd .setOnClickListener (v -> {
54+ if (item .getItemId () == R .id .action_add && page .equals ("premiums" )) {
5855 Intent intent = new Intent (this , PremiumActivity .class );
5956 intent .putExtra ("FamilyId" , familyId );
6057 intent .putExtra ("PolicyId" , policyId );
6158 intent .putExtra ("RegionId" , regionId );
62- intent .putExtra ("DistrictId" , regionId );
59+ intent .putExtra ("DistrictId" , districtId );
6360 intent .putExtra ("PremiumId" , 0 );
6461 startActivity (intent );
65- });
62+ }
63+ return super .onOptionsItemSelected (item );
64+ }
65+
66+ private void initViews (){
67+ recyclerView = findViewById (R .id .recyclerPremiums );
68+ recyclerView .setLayoutManager (new LinearLayoutManager (this ));
6669 }
6770
6871 private void loadPremiums () {
6972 String premiums = ca .getPremiums (policyId );
7073 try {
7174 JSONArray premiumArray = new JSONArray (premiums );
72- PremiumAdapter adapter = new PremiumAdapter (this ,premiumArray );
75+ PremiumAdapter adapter = new PremiumAdapter (this ,premiumArray , policyId , familyId , regionId , districtId );
7376 recyclerView .setAdapter (adapter );
7477 } catch (JSONException e ){
75- e . printStackTrace ( );
78+ throw new RuntimeException ( e );
7679 }
7780
7881 }
0 commit comments