Skip to content

Removed butterknife from MoreBottomSheetLoggedOutFragment #5446

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import butterknife.ButterKnife;
import butterknife.OnClick;
import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
import fr.free.nrw.commons.AboutActivity;
import fr.free.nrw.commons.CommonsApplication;
import fr.free.nrw.commons.R;
import fr.free.nrw.commons.auth.LoginActivity;
import fr.free.nrw.commons.databinding.FragmentMoreBottomSheetLoggedOutBinding;
import fr.free.nrw.commons.di.ApplicationlessInjection;
import fr.free.nrw.commons.kvstore.JsonKvStore;
import fr.free.nrw.commons.logging.CommonsLogSender;
Expand All @@ -29,6 +28,7 @@

public class MoreBottomSheetLoggedOutFragment extends BottomSheetDialogFragment {

private FragmentMoreBottomSheetLoggedOutBinding binding;
@Inject
CommonsLogSender commonsLogSender;
@Inject
Expand All @@ -39,30 +39,40 @@ public class MoreBottomSheetLoggedOutFragment extends BottomSheetDialogFragment
@Override
public View onCreateView(@NonNull final LayoutInflater inflater,
@Nullable final ViewGroup container, @Nullable final Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
final View view = inflater.inflate(R.layout.fragment_more_bottom_sheet_logged_out, container, false);
ButterKnife.bind(this, view);
return view;
binding = FragmentMoreBottomSheetLoggedOutBinding.inflate(inflater, container, false);
return binding.getRoot();
}

@Override
public void onViewCreated(@NonNull final View view, @Nullable final Bundle savedInstanceState) {
binding.moreLogin.setOnClickListener(v -> onLogoutClicked());
binding.moreFeedback.setOnClickListener(v -> onFeedbackClicked());
binding.moreAbout.setOnClickListener(v -> onAboutClicked());
binding.moreSettings.setOnClickListener(v -> onSettingsClicked());
}

@Override
public void onDestroyView() {
super.onDestroyView();
binding = null;
}

@Override
public void onAttach(@NonNull final Context context) {
super.onAttach(context);
ApplicationlessInjection
.getInstance(getActivity().getApplicationContext())
.getInstance(requireActivity().getApplicationContext())
.getCommonsApplicationComponent()
.inject(this);
}

@OnClick(R.id.more_login)
public void onLogoutClicked() {
applicationKvStore.putBoolean("login_skipped", false);
Intent intent = new Intent(getContext(), LoginActivity.class);
getActivity().finish(); //Kill the activity from which you will go to next activity
final Intent intent = new Intent(getContext(), LoginActivity.class);
requireActivity().finish(); //Kill the activity from which you will go to next activity
startActivity(intent);
}

@OnClick(R.id.more_feedback)
public void onFeedbackClicked() {
showAlertDialog();
}
Expand All @@ -71,7 +81,7 @@ public void onFeedbackClicked() {
* This method shows the alert dialog when a user wants to send feedback about the app.
*/
private void showAlertDialog() {
new AlertDialog.Builder(getActivity())
new AlertDialog.Builder(requireActivity())
.setMessage(R.string.feedback_sharing_data_alert)
.setCancelable(false)
.setPositiveButton(R.string.ok, (dialog, which) -> {
Expand All @@ -81,8 +91,8 @@ private void showAlertDialog() {
}

/**
* This method collects the feedback message and starts and activity with implicit intent
* to available email client.
* This method collects the feedback message and starts and activity with implicit intent to
* available email client.
*/
private void sendFeedback() {
final String technicalInfo = commonsLogSender.getExtraInfo();
Expand All @@ -103,18 +113,16 @@ private void sendFeedback() {
}
}

@OnClick(R.id.more_about)
public void onAboutClicked() {
final Intent intent = new Intent(getActivity(), AboutActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_SINGLE_TOP);
getActivity().startActivity(intent);
requireActivity().startActivity(intent);
}

@OnClick(R.id.more_settings)
public void onSettingsClicked() {
final Intent intent = new Intent(getActivity(), SettingsActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_SINGLE_TOP);
getActivity().startActivity(intent);
requireActivity().startActivity(intent);
}

private class BaseLogoutListener implements CommonsApplication.LogoutListener {
Expand All @@ -127,7 +135,7 @@ public void onLogoutComplete() {
nearbyIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
nearbyIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(nearbyIntent);
getActivity().finish();
requireActivity().finish();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,77 +1,60 @@
package fr.free.nrw.commons.navtab

import android.content.Context
import android.os.Looper
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentTransaction
import androidx.test.core.app.ApplicationProvider
import androidx.fragment.app.testing.FragmentScenario
import androidx.fragment.app.testing.launchFragmentInContainer
import androidx.lifecycle.Lifecycle
import androidx.test.ext.junit.runners.AndroidJUnit4
import fr.free.nrw.commons.TestCommonsApplication
import fr.free.nrw.commons.profile.ProfileActivity
import org.junit.Assert
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.Robolectric
import org.robolectric.RobolectricTestRunner
import org.robolectric.Shadows
import org.robolectric.annotation.Config
import org.robolectric.annotation.LooperMode
import fr.free.nrw.commons.R

@RunWith(RobolectricTestRunner::class)
@RunWith(AndroidJUnit4::class)
@Config(sdk = [21], application = TestCommonsApplication::class)
@LooperMode(LooperMode.Mode.PAUSED)
class MoreBottomSheetLoggedOutFragmentUnitTests {

private lateinit var fragment: MoreBottomSheetLoggedOutFragment

private lateinit var context: Context
private lateinit var scenario: FragmentScenario<MoreBottomSheetLoggedOutFragment>

@Before
fun setUp() {

context = ApplicationProvider.getApplicationContext()

val activity = Robolectric.buildActivity(ProfileActivity::class.java).create().get()
fragment = MoreBottomSheetLoggedOutFragment()
val fragmentManager: FragmentManager = activity.supportFragmentManager
val fragmentTransaction: FragmentTransaction = fragmentManager.beginTransaction()
fragmentTransaction.add(fragment, null)
fragmentTransaction.commit()

}

@Test
@Throws(Exception::class)
fun checkFragmentNotNull() {
Assert.assertNotNull(fragment)
scenario = launchFragmentInContainer(
initialState = Lifecycle.State.RESUMED,
themeResId = R.style.LightAppTheme
) {
MoreBottomSheetLoggedOutFragment()
}
}

@Test
@Throws(Exception::class)
fun testOnSettingsClicked() {
Shadows.shadowOf(Looper.getMainLooper()).idle()
fragment.onSettingsClicked()
scenario.onFragment { it.onSettingsClicked() }
}

@Test
@Throws(Exception::class)
fun testOnAboutClicked() {
Shadows.shadowOf(Looper.getMainLooper()).idle()
fragment.onAboutClicked()
scenario.onFragment { it.onAboutClicked() }
}

@Test
@Throws(Exception::class)
fun testOnFeedbackClicked() {
Shadows.shadowOf(Looper.getMainLooper()).idle()
fragment.onFeedbackClicked()
scenario.onFragment { it.onFeedbackClicked() }
}

@Test
@Throws(Exception::class)
fun testOnLogoutClicked() {
Shadows.shadowOf(Looper.getMainLooper()).idle()
fragment.onLogoutClicked()
scenario.onFragment { it.onLogoutClicked() }
}

}