|
6 | 6 | import android.view.MenuItem; |
7 | 7 | import android.view.View; |
8 | 8 | import android.view.ViewGroup; |
9 | | -import android.widget.TextView; |
10 | 9 |
|
11 | 10 | import androidx.annotation.NonNull; |
12 | 11 | import androidx.appcompat.app.AppCompatActivity; |
13 | | -import androidx.appcompat.widget.Toolbar; |
14 | 12 | import androidx.fragment.app.Fragment; |
15 | 13 | import androidx.fragment.app.FragmentActivity; |
16 | | -import androidx.recyclerview.widget.RecyclerView; |
17 | 14 | import androidx.viewpager2.adapter.FragmentStateAdapter; |
18 | | -import androidx.viewpager2.widget.ViewPager2; |
19 | 15 |
|
20 | | -import com.google.android.material.tabs.TabLayout; |
21 | 16 | import com.google.android.material.tabs.TabLayoutMediator; |
22 | 17 |
|
23 | 18 | import org.schabi.newpipe.BuildConfig; |
24 | 19 | import org.schabi.newpipe.R; |
| 20 | +import org.schabi.newpipe.databinding.ActivityAboutBinding; |
| 21 | +import org.schabi.newpipe.databinding.FragmentAboutBinding; |
25 | 22 | import org.schabi.newpipe.util.ThemeHelper; |
26 | 23 |
|
27 | 24 | import static org.schabi.newpipe.util.Localization.assureCorrectAppLanguage; |
@@ -68,40 +65,27 @@ public class AboutActivity extends AppCompatActivity { |
68 | 65 | private static final int POS_ABOUT = 0; |
69 | 66 | private static final int POS_LICENSE = 1; |
70 | 67 | private static final int TOTAL_COUNT = 2; |
71 | | - /** |
72 | | - * The {@link RecyclerView.Adapter} that will provide |
73 | | - * fragments for each of the sections. We use a |
74 | | - * {@link FragmentStateAdapter} derivative, which will keep every |
75 | | - * loaded fragment in memory. |
76 | | - */ |
77 | | - private SectionsPagerAdapter mSectionsPagerAdapter; |
78 | | - /** |
79 | | - * The {@link ViewPager2} that will host the section contents. |
80 | | - */ |
81 | | - private ViewPager2 mViewPager; |
82 | 68 |
|
83 | 69 | @Override |
84 | 70 | protected void onCreate(final Bundle savedInstanceState) { |
85 | 71 | assureCorrectAppLanguage(this); |
86 | 72 | super.onCreate(savedInstanceState); |
87 | 73 | ThemeHelper.setTheme(this); |
88 | | - this.setTitle(getString(R.string.title_activity_about)); |
| 74 | + setTitle(getString(R.string.title_activity_about)); |
89 | 75 |
|
90 | | - setContentView(R.layout.activity_about); |
| 76 | + final ActivityAboutBinding aboutBinding = ActivityAboutBinding.inflate(getLayoutInflater()); |
| 77 | + setContentView(aboutBinding.getRoot()); |
91 | 78 |
|
92 | | - final Toolbar toolbar = findViewById(R.id.toolbar); |
93 | | - setSupportActionBar(toolbar); |
| 79 | + setSupportActionBar(aboutBinding.toolbar); |
94 | 80 | getSupportActionBar().setDisplayHomeAsUpEnabled(true); |
95 | 81 | // Create the adapter that will return a fragment for each of the three |
96 | 82 | // primary sections of the activity. |
97 | | - mSectionsPagerAdapter = new SectionsPagerAdapter(this); |
| 83 | + final SectionsPagerAdapter mSectionsPagerAdapter = new SectionsPagerAdapter(this); |
98 | 84 |
|
99 | 85 | // Set up the ViewPager with the sections adapter. |
100 | | - mViewPager = findViewById(R.id.container); |
101 | | - mViewPager.setAdapter(mSectionsPagerAdapter); |
| 86 | + aboutBinding.container.setAdapter(mSectionsPagerAdapter); |
102 | 87 |
|
103 | | - final TabLayout tabLayout = findViewById(R.id.tabs); |
104 | | - new TabLayoutMediator(tabLayout, mViewPager, (tab, position) -> { |
| 88 | + new TabLayoutMediator(aboutBinding.tabs, aboutBinding.container, (tab, position) -> { |
105 | 89 | switch (position) { |
106 | 90 | default: |
107 | 91 | case POS_ABOUT: |
@@ -143,33 +127,28 @@ public static AboutFragment newInstance() { |
143 | 127 | } |
144 | 128 |
|
145 | 129 | @Override |
146 | | - public View onCreateView(final LayoutInflater inflater, final ViewGroup container, |
| 130 | + public View onCreateView(@NonNull final LayoutInflater inflater, final ViewGroup container, |
147 | 131 | final Bundle savedInstanceState) { |
148 | | - final View rootView = inflater.inflate(R.layout.fragment_about, container, false); |
149 | | - final Context context = this.getContext(); |
| 132 | + final FragmentAboutBinding aboutBinding = |
| 133 | + FragmentAboutBinding.inflate(inflater, container, false); |
| 134 | + final Context context = getContext(); |
150 | 135 |
|
151 | | - final TextView version = rootView.findViewById(R.id.app_version); |
152 | | - version.setText(BuildConfig.VERSION_NAME); |
| 136 | + aboutBinding.appVersion.setText(BuildConfig.VERSION_NAME); |
153 | 137 |
|
154 | | - final View githubLink = rootView.findViewById(R.id.github_link); |
155 | | - githubLink.setOnClickListener(nv -> |
| 138 | + aboutBinding.githubLink.setOnClickListener(nv -> |
156 | 139 | openUrlInBrowser(context, context.getString(R.string.github_url))); |
157 | 140 |
|
158 | | - final View donationLink = rootView.findViewById(R.id.donation_link); |
159 | | - donationLink.setOnClickListener(v -> |
| 141 | + aboutBinding.donationLink.setOnClickListener(v -> |
160 | 142 | openUrlInBrowser(context, context.getString(R.string.donation_url))); |
161 | 143 |
|
162 | | - final View websiteLink = rootView.findViewById(R.id.website_link); |
163 | | - websiteLink.setOnClickListener(nv -> |
| 144 | + aboutBinding.websiteLink.setOnClickListener(nv -> |
164 | 145 | openUrlInBrowser(context, context.getString(R.string.website_url))); |
165 | 146 |
|
166 | | - final View privacyPolicyLink = rootView.findViewById(R.id.privacy_policy_link); |
167 | | - privacyPolicyLink.setOnClickListener(v -> |
| 147 | + aboutBinding.privacyPolicyLink.setOnClickListener(v -> |
168 | 148 | openUrlInBrowser(context, context.getString(R.string.privacy_policy_url))); |
169 | 149 |
|
170 | | - return rootView; |
| 150 | + return aboutBinding.getRoot(); |
171 | 151 | } |
172 | | - |
173 | 152 | } |
174 | 153 |
|
175 | 154 | /** |
|
0 commit comments