「午前 12時」が「12 P.M.」とか

12

まさか、 「11AM」 の一時間後が 「12PM」 だなんて...

よく見かけるので調べてみたら...


<?php
date_default_timezone_set('UTC');
//date_default_timezone_set('Asia/Tokyo');

for ($h = 0; $h < 24; $h++) {
  $time = $h * 60 * 60;
  printf('%s - %s - %s %s' . "\n",
         date('H:i',   $time),
         date('h:i a', $time),
         date('h:i A', $time),
         $h % 12 === 0 ? '*' : '');
}

PHP: date - Manual


00:00 - 12:00 am - 12:00 AM *
01:00 - 01:00 am - 01:00 AM 
02:00 - 02:00 am - 02:00 AM 
03:00 - 03:00 am - 03:00 AM 
04:00 - 04:00 am - 04:00 AM 
05:00 - 05:00 am - 05:00 AM 
06:00 - 06:00 am - 06:00 AM 
07:00 - 07:00 am - 07:00 AM 
08:00 - 08:00 am - 08:00 AM 
09:00 - 09:00 am - 09:00 AM 
10:00 - 10:00 am - 10:00 AM 
11:00 - 11:00 am - 11:00 AM 
12:00 - 12:00 pm - 12:00 PM *
13:00 - 01:00 pm - 01:00 PM 
14:00 - 02:00 pm - 02:00 PM 
15:00 - 03:00 pm - 03:00 PM 
16:00 - 04:00 pm - 04:00 PM 
17:00 - 05:00 pm - 05:00 PM 
18:00 - 06:00 pm - 06:00 PM
19:00 - 07:00 pm - 07:00 PM 
20:00 - 08:00 pm - 08:00 PM 
21:00 - 09:00 pm - 09:00 PM 
22:00 - 10:00 pm - 10:00 PM 
23:00 - 11:00 pm - 11:00 PM

まじか...

Usage Note: By convention, 12 AM denotes midnight and 12 PM denotes noon. Because of the potential for confusion, it is advisable to use 12 noon and 12 midnight.

American Heritage Dictionary Entry: PM

そうなのですか...

覚えておきます。


RecyclerView のアイテムの中のある部分のクリック

list_mail

まずは, 入れ子なしでばらして書かせたほうがいいような気がするのです.

java - Why doesn't RecyclerView have onItemClickListener()? And how RecyclerView is different from Listview? - Stack Overflow


public static class MyViewHolder extends RecyclerView.ViewHolder {

  public TextView text;
  public ImageView image;
  public OnClickPartsListener listener;

  public MyViewHolder(View itemView, OnClickPartsListener listener) {
    super(itemView);

    this.listener = listener;
    text = (TextView) itemView.findViewById(R.id.text);
    image = (ImageView) itemView.findViewById(R.id.image);

    text.setOnClickListener(new View.OnClickListener {
      listener.onClickText("Text Clicked!!");
    });

    image.setOnClickListener(new View.OnClickListener {
      listener.onClickImage("Image Clicked!!");
    });

  }

  public interface OnClickPartsListener {
    void onClickText(String message);
    void onClickImage(String message);
  }

}


public class MyAdapter extends RecyclerView.Adapter<MyViewHolder> {

  private MyViewHolder.OnClickPartsListener listener;

  public MyAdapter(MyViewHolder.OnClickPartsListener listener) {
    this.listener = listener;
  }

  @Override
  public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    //..	 
    return new MyViewHolder(view, listener);
  }

}


public class MyActivity extends AppCompatActivity {  
  
  @Override  
  protected void onCreate(Bundle savedInstanceState) {  

    MyViewHolder.OnClickPartsListener listener =
      new MyViewHolder.OnClickPartsListener() {
  
        public void onClickText(String message) {
          Toast.makeText(this, message, LENGTH_SHORT).show();  
        }

        public void onClickImage(String message) {
          Toast.makeText(this, message, LENGTH_SHORT).show();  
        }

      };

    recyclerView = (RecyclerView) findViewById(R.id.recycler_view);  
    adapter = new MyAdapter(listener) {  
    recyclerView.setAdapter(adapter);  

  }

}

めんどくさいので,


public class MyAdapter extends RecyclerView.Adapter<MyViewHolder> {

  private final PublishSubject<String> onClickSubject = PublishSubject.create();

  @Override 
  public void onBindViewHolder(final ViewHolder holder, int position) {

    final Item item = items.get(position);

    holder.itemView.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
        onClickSubject.onNext(item);
      }
    });
  }

  public Observable<String> getPositionClicks(){
    return onClickSubject.asObservable();
  }

}

または, イベントバス..

まとめ

親や祖父母側で実装した子や孫のインターフェースをコンストラクタ経由で渡し返す.

tag を上手に使うとよい.


よくある Observable の入れ子ができない頭の硬さ乙

99

なぜか長ったらしくなる Observable のネスト.


Observable.just("yo")
    .flatMap(s -> Observable.range(0, 100))
    .subscribe(integer -> Ln.d("Here's an Integer(%s), but how do I access that juicy String?", integer));

Passing composite data through flatMap and similar operators without creating container objects · Issue #2931 · ReactiveX/RxJava

よくあるくせに綺麗に書けない.

そんなわたし乙.

lambda も絡めてゆっくりと眺める.

元.


Observable.just("yo")
    .flatMap(new Func1<String, Observable<? extends Integer>>() {
      @Override public Observable<? extends Integer> call(String s) {
        return Observable.range(0, 100);
      }
    })
    .map(new Func1<Integer, String>() {
      @Override public String call(Integer integer) {
        return String.format("Here's an Integer(%s), but how do I access that juicy String?", integer);
      }
    })
    .subscribe(new Action1<String>() {
      @Override public void call(String x) {
        System.out.println(x);
      }
    });

flatMap(Func1, Func2) でやる場合.


Observable.just("yo")
    .flatMap(new Func1<String, Observable<? extends Integer>>() {
      @Override public Observable<? extends Integer> call(String s) {
        return Observable.range(0, 100);
      }
    }, new Func2<String, Integer, String>() {
      @Override public String call(String s, Integer integer) {
        return String.format("Here's an Integer(%s), with String(%s)", integer, s);
      }
    })
    .subscribe(new Action1<String>() {
      @Override public void call(String x) {
        System.out.println(x);
      }
    });

flatmap に map を入れ子でやる場合.


Observable.just("yo")
    .flatMap(new Func1<String, Observable<? extends String>>() {
      @Override public Observable<? extends String> call(String s) {
        return Observable.range(0, 100)
            .map(new Func1<Integer, String>() {
              @Override public String call(Integer integer) {
                return String.format("Here's an Integer(%s), with String(%s)", integer, s);
              }
            });
      }
    })
    .subscribe(new Action1<String>() {
      @Override public void call(String x) {
        System.out.println(x);
      }
    });
  }

lambda へ

元.


Observable.just("yo")
    .flatMap(s -> Observable.range(0, 100))
    .map(integer -> String.format("Here's an Integer(%s), but how do I access that juicy String?", integer))
    .subscribe(System.out::println);

flatMap(Func1, Func2) でやる場合.


Observable.just("yo")
    .flatMap(s -> Observable.range(0, 100),
        (s, integer) -> String.format("Here's an Integer(%s), with String(%s)", integer, s))
    .subscribe(System.out::println);

flatmap に map を入れ子でやる場合.


Observable.just("yo")
    .flatMap(s -> Observable.range(0, 100)
        .map(integer -> String.format("Here's an Integer(%s), with String(%s)", integer, s)))
    .subscribe(System.out::println);

まとめ

flatmap に map を入れるのがわかりやすいように思います.

慣れたらラムダも直感的です.

Feature request: @Passthru variable for Rx chains · Issue #855 · square/retrofit