ahmedeltaher / Prayer-Times-Android-Azan

Prayer + Time + Android + Kotlin + Azan + Library + timezone + islamic + salah + Library aiming to calculate prayer time with one line code , if you implement prayer time application , there is no need to do this headache again .
Apache License 2.0
364 stars 96 forks source link

PrayerTimes return null #10

Closed Xoshbin closed 5 years ago

Xoshbin commented 6 years ago

Hi, I'm trying to use this library in my APP, but I think it returns null instead of the time, The code below is how I used it in my fragment:

public class PrayerFragment extends Fragment {

    Date fajr;
    Date sunrise;
    Date zuhr;
    Date maghrib;
    Date isha;

    public PrayerFragment() {
        // Required empty public constructor
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_prayer, container, false);
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        GregorianCalendar date = new GregorianCalendar();

        PrayerTimes prayerTimes = new TimeCalculator().date(date).location(-6.38043079,106.85337984, 0,7).timeCalculationMethod(EGYPT).calculateTimes();

        prayerTimes.setUseSecond(true);

        fajr = prayerTimes.getPrayTime(PrayersType.FAJR);

        sunrise = prayerTimes.getPrayTime(PrayersType.SUNRISE);

        zuhr = prayerTimes.getPrayTime(PrayersType.ZUHR);

        maghrib = prayerTimes.getPrayTime(PrayersType.MAGHRIB);

        isha = prayerTimes.getPrayTime(PrayersType.ISHA);

    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        if (fajr != null) {
            TextView textView = (TextView) getView().findViewById(R.id.fajr);
            textView.setText((CharSequence) fajr);
        }else{
            Toast.makeText(getContext().getApplicationContext(), "LOL", Toast.LENGTH_LONG).show();
        }
    }
}
ahmedeltaher commented 5 years ago

it is reproduce in my side, I have tried your code, and I got results.

Screenshot 2019-04-14 at 13 35 44