1
0
mirror of https://github.com/TeamNewPipe/NewPipe.git synced 2024-11-25 20:42:34 +01:00

Use view binding in AboutActivity.

This commit is contained in:
Isira Seneviratne 2020-10-31 11:34:48 +05:30
parent ba0c0fb109
commit 4545b8e92d

View File

@ -6,22 +6,19 @@ import android.view.LayoutInflater;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentActivity;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager2.adapter.FragmentStateAdapter; import androidx.viewpager2.adapter.FragmentStateAdapter;
import androidx.viewpager2.widget.ViewPager2;
import com.google.android.material.tabs.TabLayout;
import com.google.android.material.tabs.TabLayoutMediator; import com.google.android.material.tabs.TabLayoutMediator;
import org.schabi.newpipe.BuildConfig; import org.schabi.newpipe.BuildConfig;
import org.schabi.newpipe.R; import org.schabi.newpipe.R;
import org.schabi.newpipe.databinding.ActivityAboutBinding;
import org.schabi.newpipe.databinding.FragmentAboutBinding;
import org.schabi.newpipe.util.ThemeHelper; import org.schabi.newpipe.util.ThemeHelper;
import static org.schabi.newpipe.util.Localization.assureCorrectAppLanguage; import static org.schabi.newpipe.util.Localization.assureCorrectAppLanguage;
@ -68,40 +65,27 @@ public class AboutActivity extends AppCompatActivity {
private static final int POS_ABOUT = 0; private static final int POS_ABOUT = 0;
private static final int POS_LICENSE = 1; private static final int POS_LICENSE = 1;
private static final int TOTAL_COUNT = 2; private static final int TOTAL_COUNT = 2;
/**
* The {@link RecyclerView.Adapter} that will provide
* fragments for each of the sections. We use a
* {@link FragmentStateAdapter} derivative, which will keep every
* loaded fragment in memory.
*/
private SectionsPagerAdapter mSectionsPagerAdapter;
/**
* The {@link ViewPager2} that will host the section contents.
*/
private ViewPager2 mViewPager;
@Override @Override
protected void onCreate(final Bundle savedInstanceState) { protected void onCreate(final Bundle savedInstanceState) {
assureCorrectAppLanguage(this); assureCorrectAppLanguage(this);
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
ThemeHelper.setTheme(this); ThemeHelper.setTheme(this);
this.setTitle(getString(R.string.title_activity_about)); setTitle(getString(R.string.title_activity_about));
setContentView(R.layout.activity_about); final ActivityAboutBinding aboutBinding = ActivityAboutBinding.inflate(getLayoutInflater());
setContentView(aboutBinding.getRoot());
final Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(aboutBinding.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
// Create the adapter that will return a fragment for each of the three // Create the adapter that will return a fragment for each of the three
// primary sections of the activity. // primary sections of the activity.
mSectionsPagerAdapter = new SectionsPagerAdapter(this); final SectionsPagerAdapter mSectionsPagerAdapter = new SectionsPagerAdapter(this);
// Set up the ViewPager with the sections adapter. // Set up the ViewPager with the sections adapter.
mViewPager = findViewById(R.id.container); aboutBinding.container.setAdapter(mSectionsPagerAdapter);
mViewPager.setAdapter(mSectionsPagerAdapter);
final TabLayout tabLayout = findViewById(R.id.tabs); new TabLayoutMediator(aboutBinding.tabs, aboutBinding.container, (tab, position) -> {
new TabLayoutMediator(tabLayout, mViewPager, (tab, position) -> {
switch (position) { switch (position) {
default: default:
case POS_ABOUT: case POS_ABOUT:
@ -143,33 +127,28 @@ public class AboutActivity extends AppCompatActivity {
} }
@Override @Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container, public View onCreateView(@NonNull final LayoutInflater inflater, final ViewGroup container,
final Bundle savedInstanceState) { final Bundle savedInstanceState) {
final View rootView = inflater.inflate(R.layout.fragment_about, container, false); final FragmentAboutBinding aboutBinding =
final Context context = this.getContext(); FragmentAboutBinding.inflate(inflater, container, false);
final Context context = getContext();
final TextView version = rootView.findViewById(R.id.app_version); aboutBinding.appVersion.setText(BuildConfig.VERSION_NAME);
version.setText(BuildConfig.VERSION_NAME);
final View githubLink = rootView.findViewById(R.id.github_link); aboutBinding.githubLink.setOnClickListener(nv ->
githubLink.setOnClickListener(nv ->
openUrlInBrowser(context, context.getString(R.string.github_url))); openUrlInBrowser(context, context.getString(R.string.github_url)));
final View donationLink = rootView.findViewById(R.id.donation_link); aboutBinding.donationLink.setOnClickListener(v ->
donationLink.setOnClickListener(v ->
openUrlInBrowser(context, context.getString(R.string.donation_url))); openUrlInBrowser(context, context.getString(R.string.donation_url)));
final View websiteLink = rootView.findViewById(R.id.website_link); aboutBinding.websiteLink.setOnClickListener(nv ->
websiteLink.setOnClickListener(nv ->
openUrlInBrowser(context, context.getString(R.string.website_url))); openUrlInBrowser(context, context.getString(R.string.website_url)));
final View privacyPolicyLink = rootView.findViewById(R.id.privacy_policy_link); aboutBinding.privacyPolicyLink.setOnClickListener(v ->
privacyPolicyLink.setOnClickListener(v ->
openUrlInBrowser(context, context.getString(R.string.privacy_policy_url))); openUrlInBrowser(context, context.getString(R.string.privacy_policy_url)));
return rootView; return aboutBinding.getRoot();
} }
} }
/** /**