|
| 1 | +package com.futurist_labs.android.base_library.ui.versions; |
| 2 | + |
| 3 | + |
| 4 | +import android.content.Context; |
| 5 | +import android.graphics.Color; |
| 6 | +import android.graphics.drawable.ColorDrawable; |
| 7 | +import android.os.Bundle; |
| 8 | +import android.support.annotation.NonNull; |
| 9 | +import android.support.annotation.Nullable; |
| 10 | +import android.support.v4.app.DialogFragment; |
| 11 | +import android.support.v4.app.Fragment; |
| 12 | +import android.view.LayoutInflater; |
| 13 | +import android.view.View; |
| 14 | +import android.view.ViewGroup; |
| 15 | +import android.view.Window; |
| 16 | + |
| 17 | +import com.futurist_labs.android.base_library.R; |
| 18 | +import com.futurist_labs.android.base_library.model.BaseLibraryConfiguration; |
| 19 | +import com.futurist_labs.android.base_library.utils.IntentUtils; |
| 20 | +import com.futurist_labs.android.base_library.utils.versions.Versions; |
| 21 | +import com.futurist_labs.android.base_library.views.font_views.FontTextView; |
| 22 | + |
| 23 | +/** |
| 24 | + * A simple {@link Fragment} subclass. |
| 25 | + * Use the {@link UpdateDialogFragment#newInstance} factory method to |
| 26 | + * create an instance of this fragment. |
| 27 | + */ |
| 28 | +public class UpdateDialogFragment extends DialogFragment { |
| 29 | + private static final String ARG_VERSIONS = "param1"; |
| 30 | + private Callback callback; |
| 31 | + private Versions versions; |
| 32 | + private FontTextView tvNextTime; |
| 33 | + private FontTextView tvGoToStore; |
| 34 | + |
| 35 | + public UpdateDialogFragment() { |
| 36 | + // Required empty public constructor |
| 37 | + } |
| 38 | + |
| 39 | + public static UpdateDialogFragment newInstance(Versions versions) { |
| 40 | + UpdateDialogFragment fragment = new UpdateDialogFragment(); |
| 41 | + Bundle args = new Bundle(); |
| 42 | + args.putParcelable(ARG_VERSIONS, versions); |
| 43 | + fragment.setArguments(args); |
| 44 | + return fragment; |
| 45 | + } |
| 46 | + |
| 47 | + @Override |
| 48 | + public void onCreate(Bundle savedInstanceState) { |
| 49 | + super.onCreate(savedInstanceState); |
| 50 | + if (getArguments() != null) { |
| 51 | + versions = getArguments().getParcelable(ARG_VERSIONS); |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + @Override |
| 56 | + public void onAttach(Context context) { |
| 57 | + super.onAttach(context); |
| 58 | + if (context instanceof Callback) { |
| 59 | + callback = (Callback) context; |
| 60 | + } else { |
| 61 | + throw new RuntimeException(context.toString() |
| 62 | + + " must implement Callback"); |
| 63 | + } |
| 64 | + } |
| 65 | + |
| 66 | + @Override |
| 67 | + public void onDetach() { |
| 68 | + super.onDetach(); |
| 69 | + callback = null; |
| 70 | + } |
| 71 | + |
| 72 | + @Override |
| 73 | + public View onCreateView(LayoutInflater inflater, ViewGroup container, |
| 74 | + Bundle savedInstanceState) { |
| 75 | + getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE); |
| 76 | + getDialog().setCancelable(false); |
| 77 | + if (getDialog().getWindow() != null) { |
| 78 | + getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); |
| 79 | + } |
| 80 | + // Inflate the layout for this fragment |
| 81 | + View view = inflater.inflate(R.layout.fragment_update_dialog, container, false); |
| 82 | + initView(view); |
| 83 | + return view; |
| 84 | + } |
| 85 | + |
| 86 | + @Override |
| 87 | + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { |
| 88 | + super.onViewCreated(view, savedInstanceState); |
| 89 | +// setCancelable(false); |
| 90 | + |
| 91 | + tvNextTime.setOnClickListener(new View.OnClickListener() { |
| 92 | + @Override |
| 93 | + public void onClick(View v) { |
| 94 | + dismiss(); |
| 95 | + if (callback != null) { |
| 96 | + callback.onDismiss(); |
| 97 | + } |
| 98 | + } |
| 99 | + }); |
| 100 | + |
| 101 | + tvGoToStore.setOnClickListener(new View.OnClickListener() { |
| 102 | + @Override |
| 103 | + public void onClick(View v) { |
| 104 | + IntentUtils.openAppInPlayStore(getContext(), |
| 105 | + BaseLibraryConfiguration.getInstance().APPLICATION_ID); |
| 106 | + if (callback != null) { |
| 107 | + callback.goToStore(); |
| 108 | + } |
| 109 | + dismiss(); |
| 110 | + } |
| 111 | + }); |
| 112 | + } |
| 113 | + |
| 114 | + private void initView(View view) { |
| 115 | + tvNextTime = view.findViewById(R.id.tvNextTime); |
| 116 | + tvGoToStore = view.findViewById(R.id.tvGoToStore); |
| 117 | + } |
| 118 | + |
| 119 | + |
| 120 | + public interface Callback { |
| 121 | + void onDismiss(); |
| 122 | + |
| 123 | + void goToStore(); |
| 124 | + } |
| 125 | +} |
0 commit comments