Skip to content

Commit 8f30865

Browse files
committed
add Activity, DialogFragment and Fragment
1 parent 06d02a0 commit 8f30865

File tree

4 files changed

+216
-0
lines changed

4 files changed

+216
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
Author: UB
3+
Version: v1.0
4+
Date: March 2, 2021
5+
*/
6+
7+
package com.isolpro.custom;
8+
9+
import android.os.Bundle;
10+
import android.view.View;
11+
12+
import androidx.annotation.Nullable;
13+
import androidx.appcompat.app.AppCompatActivity;
14+
import androidx.viewbinding.ViewBinding;
15+
16+
public abstract class Activity<B> extends AppCompatActivity {
17+
18+
protected android.app.Activity activity;
19+
20+
protected B binding;
21+
22+
@Override
23+
protected void onCreate(@Nullable Bundle savedInstanceState) {
24+
super.onCreate(savedInstanceState);
25+
26+
activity = this;
27+
}
28+
29+
public void setContentBinding(B binding) {
30+
this.binding = binding;
31+
super.setContentView(((ViewBinding) binding).getRoot());
32+
}
33+
34+
public void setContentResource(int layoutResource) {
35+
super.setContentView(layoutResource);
36+
}
37+
38+
public void setContentView(View view) {
39+
super.setContentView(view);
40+
}
41+
42+
protected void begin() {
43+
instantiate();
44+
initialize();
45+
listen();
46+
load();
47+
}
48+
49+
protected abstract void instantiate();
50+
51+
protected abstract void initialize();
52+
53+
protected abstract void listen();
54+
55+
protected abstract void load();
56+
57+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
Author: UB
3+
Version: v1.0
4+
Date: March 2, 2021
5+
*/
6+
7+
package com.isolpro.custom;
8+
9+
import android.app.Activity;
10+
import android.content.Intent;
11+
import android.os.Bundle;
12+
import android.view.LayoutInflater;
13+
import android.view.View;
14+
import android.view.ViewGroup;
15+
16+
import androidx.annotation.NonNull;
17+
import androidx.annotation.Nullable;
18+
import androidx.viewbinding.ViewBinding;
19+
20+
public abstract class DialogFragment<B> extends androidx.fragment.app.DialogFragment {
21+
22+
protected Activity activity;
23+
24+
protected B binding;
25+
private View mv;
26+
27+
@Override
28+
public void onCreate(@Nullable Bundle savedInstanceState) {
29+
super.onCreate(savedInstanceState);
30+
31+
activity = getActivity();
32+
33+
setStyle(STYLE_NO_FRAME, R.style.CustomDialog);
34+
}
35+
36+
@Nullable
37+
@Override
38+
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
39+
activity = getActivity();
40+
41+
return mv;
42+
}
43+
44+
public void setContentBinding(B binding) {
45+
this.binding = binding;
46+
mv = ((ViewBinding) binding).getRoot();
47+
}
48+
49+
public void setContentResource(int layoutResource) {
50+
mv = getLayoutInflater().inflate(layoutResource, null);
51+
}
52+
53+
public void setContentView(View view) {
54+
mv = view;
55+
}
56+
57+
protected void begin() {
58+
instantiate();
59+
initialize();
60+
listen();
61+
load();
62+
}
63+
64+
protected abstract void instantiate();
65+
66+
protected abstract void initialize();
67+
68+
protected abstract void listen();
69+
70+
protected abstract void load();
71+
72+
public void dismiss(int requestCode, int resultCode, Intent data) {
73+
if (getTargetFragment() != null)
74+
getTargetFragment().onActivityResult(requestCode, resultCode, data);
75+
76+
dismiss();
77+
}
78+
79+
public void onBackPressed() {
80+
activity.onBackPressed();
81+
}
82+
83+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
Author: UB
3+
Version: v1.0
4+
Date: March 2, 2021
5+
*/
6+
7+
package com.isolpro.custom;
8+
9+
import android.app.Activity;
10+
import android.os.Bundle;
11+
import android.view.LayoutInflater;
12+
import android.view.View;
13+
import android.view.ViewGroup;
14+
15+
import androidx.annotation.NonNull;
16+
import androidx.annotation.Nullable;
17+
import androidx.viewbinding.ViewBinding;
18+
19+
public abstract class Fragment<B> extends androidx.fragment.app.Fragment {
20+
21+
protected Activity activity;
22+
23+
protected B binding;
24+
private View mv;
25+
26+
@Override
27+
public void onCreate(@Nullable Bundle savedInstanceState) {
28+
super.onCreate(savedInstanceState);
29+
30+
activity = getActivity();
31+
}
32+
33+
@Nullable
34+
@Override
35+
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
36+
return mv;
37+
}
38+
39+
public void setContentBinding(B binding) {
40+
this.binding = binding;
41+
mv = ((ViewBinding) binding).getRoot();
42+
}
43+
44+
public void setContentResource(int layoutResource) {
45+
mv = getLayoutInflater().inflate(layoutResource, null);
46+
}
47+
48+
public void setContentView(View view) {
49+
mv = view;
50+
}
51+
52+
protected void begin() {
53+
instantiate();
54+
initialize();
55+
listen();
56+
load();
57+
}
58+
59+
protected abstract void instantiate();
60+
61+
protected abstract void initialize();
62+
63+
protected abstract void listen();
64+
65+
protected abstract void load();
66+
67+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<resources>
2+
3+
<style name="CustomDialog" parent="Theme.MaterialComponents.Light.Dialog">
4+
<item name="android:windowBackground">@android:color/transparent</item>
5+
<item name="android:windowNoTitle">true</item>
6+
<item name="android:windowIsFloating">true</item>
7+
</style>
8+
9+
</resources>

0 commit comments

Comments
 (0)